Instantly share code, notes, and snippets.

Embed
What would you like to do?
Puppeteer - Scrape smadeseek.com 2 levels deep
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