Created
October 24, 2017 17:03
-
-
Save bmorelli25/faf3c7f1c67bb82cd23224bba1620764 to your computer and use it in GitHub Desktop.
scrape.js completed
This file contains hidden or 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 puppeteer = require('puppeteer'); | |
| let scrape = async () => { | |
| const browser = await puppeteer.launch({headless: false}); | |
| const page = await browser.newPage(); | |
| await page.goto('http://books.toscrape.com/'); | |
| await page.click('#default > div > div > div > div > section > div:nth-child(2) > ol > li:nth-child(1) > article > div.image_container > a > img'); | |
| await page.waitFor(1000); | |
| const result = await page.evaluate(() => { | |
| let title = document.querySelector('h1').innerText; | |
| let price = document.querySelector('.price_color').innerText; | |
| return { | |
| title, | |
| price | |
| } | |
| }); | |
| browser.close(); | |
| return result; | |
| }; | |
| scrape().then((value) => { | |
| console.log(value); // Success! | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment