Skip to content

Instantly share code, notes, and snippets.

@uladzislau-stuk
Last active October 15, 2019 18:45
Show Gist options
  • Save uladzislau-stuk/a9a9aef93ece5dd82e7ee89ab9a28171 to your computer and use it in GitHub Desktop.
Save uladzislau-stuk/a9a9aef93ece5dd82e7ee89ab9a28171 to your computer and use it in GitHub Desktop.
Puppeteer

Tricks

Get element attribute

// by xpath
const [elementHandle] = await page.$x('.//a/@href');
const propertyHandle = await elementHandle.getProperty('value');
const propertyValue = await propertyHandle.jsonValue();

// by .jsonValue()
const [elementHandle] = await page.$x('.//a');
const propertyHandle = await elementHandle.getProperty('innerText');
const propertyValue = await propertyHandle.jsonValue();

Articles

Tips and Tricks for Web Scraping with Puppeteer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment