Created
November 23, 2017 11:57
-
-
Save nikosvaggalis/05198cbf041f5e89358d55b3693ebc6f to your computer and use it in GitHub Desktop.
Puppeteer - Scrape smadeseek.com 2 levels deep
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 puppeteer = require("puppeteer"); | |
const url = "http://smadeseek.com/smartphones"; | |
const imgSelector = "#contentx > div > div img"; | |
const tableSelector = "#masthead"; | |
const tableSelector2 = "#masthead > div > div:nth-child(2) > div > div > div.col-md-6.col-sm-6 > table:nth-child(2)"; | |
(async () => { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto(url, { waitUntil: ["load","domcontentloaded"] }); | |
await page.waitForSelector(imgSelector); | |
const imgAll = await page.$$eval(imgSelector, images => {return images.map((image)=>image.src)}); | |
await console.log(imgAll); | |
await page.click("#contentx > div > div:nth-child(2) > a > img "); | |
await page.waitForSelector(tableSelector); | |
const tableAll = await page.$eval(tableSelector2, images => images.innerHTML); | |
await console.log(tableAll); | |
await browser.close(); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment