Skip to content

Instantly share code, notes, and snippets.

@ysmood
Last active September 20, 2020 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysmood/12e08d716817b2afa681ba3b9faf97c9 to your computer and use it in GitHub Desktop.
Save ysmood/12e08d716817b2afa681ba3b9faf97c9 to your computer and use it in GitHub Desktop.
const puppeteer = require('puppeteer')
;(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
// Total timeout for all operations is not supported, only supports timeout for individual operations.
// Puppeteer doesn't support aborting of slow operation.
page.setDefaultTimeout(5 * 1000)
await page.goto('https://github.com/avelino/awesome-go')
const p = await page.waitForXPath(`//p[text()[contains(., 'Selenium and browser control tools.')]]`)
const section = await p.evaluateHandle(el => el.nextElementSibling)
const projects = await section.$$('li')
for (const project of projects) {
const link = await project.$('a')
console.log(
"project %s (%s): '%s'",
await link.evaluate(el => el.innerText),
await link.evaluate(el => el.href),
await project.evaluate(el => el.innerText)
)
}
await browser.close()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment