-
-
Save mofas/7b6768bf7d71c08f610129df7c52986e to your computer and use it in GitHub Desktop.
Search Google
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
async function queryGoogle(target) { | |
const page = await browser.newPage(); | |
await page.goto('https://google.com'); | |
await page.keyboard.type(target + " MSA") | |
await page.keyboard.press("Enter") | |
await page.waitForNavigation(); | |
await page.content() | |
const title = await page.evaluate(() => { | |
let elements = document.querySelectorAll('h3'); | |
return elements[0].textContent; | |
}); | |
console.log(title); | |
// await page.screenshot({path: 'screenshot.png'}); | |
} | |
const browser = await puppeteer.launch(); | |
const targets = ["SF", "Nashville Tennssee", "New York"]; | |
for (target of targets){ | |
await queryGoogle(target); | |
} | |
await browser.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment