Created
March 14, 2018 21:23
-
-
Save davidohlin/fbf2d403600a0d63b6c9f59ed81b6a37 to your computer and use it in GitHub Desktop.
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'); | |
const o2c = require('objects-to-csv'); | |
const list = require('./list'); | |
const res = []; | |
(async () => { | |
const browser = await puppeteer.launch({ | |
headless: false, | |
// slowMo: 200 // slow down by 250ms | |
}); | |
const page = await browser.newPage(); | |
for (let i = 0; i < list.length; i++) { | |
let term = list[i]; | |
await page.goto('https://google.com'); | |
await page.type('#lst-ib', `site:pricerunner.se ${list[i]}`); | |
await page.keyboard.press('Enter'); | |
await page.waitForSelector('h3.r > a'); | |
let email = await page.evaluate(() => { | |
let element = document.querySelector('h3.r > a'); | |
return element.href; | |
}); | |
res.push(obj = { | |
query: list[i], | |
url: email | |
}) | |
} | |
await browser.close(); | |
let csv = new o2c(res); | |
await csv.toDisk('./test.csv'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment