Created
July 28, 2017 21:28
-
-
Save danazkari/24583f6bd2818cd763ae42af6fd5eff1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Chromeless } = require('chromeless'); | |
const log = function(arg) { console.log(arg) } | |
async function run() { | |
const chromeless = new Chromeless() | |
const links = await chromeless | |
.goto('https://www.npmjs.com') | |
.type('chromeless', 'input[name="q"]') | |
.press(13) | |
.wait('body') | |
.evaluate(() => { | |
// this will be executed in headless chrome | |
const links = [].map.call( | |
document.querySelectorAll('.search-results li'), | |
item => { | |
const { innerText: title, href } = item.querySelector('a.packageName'); | |
return { title, href }; | |
} | |
) | |
return JSON.stringify(links) | |
}) | |
console.log(links) | |
await chromeless.end() | |
} | |
run().catch(console.error.bind(console)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment