-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (57 loc) · 2.35 KB
/
index.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*jshint esversion: 6 */
const puppeteer = require('puppeteer');
const website = 'https://wallpaperscraft.com/download/black_apple_bones_skull_26511/1440x900';
console.log('puppeteer');
(async () => {
const browser = await puppeteer.launch();
//const browser = await puppeteer.launch({executablePath: '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'});
const context = browser.createIncognitoBrowserContext();
const page = await browser.newPage();
console.log('page');
await page.goto(website, {waitUntil: 'networkidle2'});
console.log('networkidle2')
await page.screenshot({path: 'img.png'});
console.log('screenshot 1');
// Type into search box.
//await page.type('#searchbox input', 'Headless Chrome');
const allResultsSelector = '.gui-button_full-height';
//await page.waitForSelector(allResultsSelector);
page.click(allResultsSelector);
console.log('clicked');
await page.waitForNavigation({waitUntil:'networkidle2'});
console.log('networkidle2');
await page.screenshot({path: 'img2.png'});
console.log('screenshot 2');
await page.goBack({waitUntil:'networkidle2'});
console.log('Going back');
await page.screenshot({path: 'img3.png'});
console.log('screenshot 3');
const wallpapers = await page.$$('.wallpapers__link');
console.log(wallpapers.length)
/*
for(let wl in wallpapers){
console.log('-------------------------\n\n\n\n\n\n\n\n\n\n\n\n\n--------------------------')
//console.log(await wallpapers[wl].href);
console.log(document.querySelector(wallpapers[wl]).href);
}
*/
const texts = await page.evaluate(() => {
return [...document.body.querySelectorAll('.wallpapers__link')]
.map(element => element.href);
});
console.log(texts);
// Wait for the results page to load and display the results.
//const resultsSelector = '.gsc-results .gsc-thumbnail-inside a.gs-title';
//await page.waitForSelector(resultsSelector);
// Extract the results from the page.
//const links = await page.evaluate(resultsSelector => {
// const anchors = Array.from(document.querySelectorAll(resultsSelector));
// return anchors.map(anchor => {
// const title = anchor.textContent.split('|')[0].trim();
// return `${title} - ${anchor.href}`;
// });
//}, resultsSelector);
//console.log(links.join('\n'));
await browser.close();
console.log('closed')
})();