-
Notifications
You must be signed in to change notification settings - Fork 0
/
google.js
30 lines (26 loc) · 980 Bytes
/
google.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const puppeteer=require('puppeteer');
const PALABRA_CLAVE = 'peru';
(async()=>{
const goto = 'https://www.google.com/';
const browser = await puppeteer.launch({headless:false});
const page = await browser.newPage();
await page.goto(goto);
await page.type('[jscontroller="vZr2rb"] [class="gLFyf gsfi"]',PALABRA_CLAVE);
await page.click('[class="FPdoLc lJ9FBc"] [class="gNO89b"]');
await page.waitForTimeout(2000)
await page.click('[class="hdtb-mitem"] [data-hveid="CAIQBQ"]')
await page.waitForTimeout(2000)
const enlaces = await page.evaluate(() => {
const elements = document.querySelectorAll('[class="fhQnRd"] div div [class="mCBkyc y355M nDgy9d"]');
const links = []
elements.forEach( (e,p) => {
const objeto = {
nombre: e.textContent
}
links.push(objeto)
})
return links;
})
console.log(enlaces)
await browser.close();
})();