Skip to content

Instantly share code, notes, and snippets.

@danazkari
Created July 28, 2017 21:28
Show Gist options
  • Save danazkari/24583f6bd2818cd763ae42af6fd5eff1 to your computer and use it in GitHub Desktop.
Save danazkari/24583f6bd2818cd763ae42af6fd5eff1 to your computer and use it in GitHub Desktop.
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