Skip to content

Instantly share code, notes, and snippets.

@mofas
Last active March 8, 2020 23:00
Show Gist options
  • Save mofas/7b6768bf7d71c08f610129df7c52986e to your computer and use it in GitHub Desktop.
Save mofas/7b6768bf7d71c08f610129df7c52986e to your computer and use it in GitHub Desktop.
Search Google
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