-
Notifications
You must be signed in to change notification settings - Fork 0
/
old.txt
56 lines (45 loc) · 1.64 KB
/
old.txt
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
const puppeteer = require("puppeteer");
const https = require("https");
const fs = require("fs");
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(
"https://www.bazakolejowa.pl/index.php?dzial=linie&id=1067&od=1&do=100&ed=0&okno=galeria"
);
await page.waitForSelector("h2#obiektNazwa");
const textContent = await page.evaluate(() => {
const element = document.querySelector("h2#obiektNazwa");
return element.textContent.trim();
});
console.log(textContent);
await page.waitForSelector("div#galeriaObrazow");
const textContent2 = await page.evaluate(() => {
const divs = document.querySelectorAll("div#galeriaObrazow div a img");
const contents = [];
divs.forEach((div) => {
contents.push(div.src.replace("addons/tempbases/thumbs", "foto"));
});
return contents;
});
console.log(textContent2);
textContent2.forEach((link, i) => {
const imageName = `img/${i+1}.jpg`
const file = fs.createWriteStream(imageName)
https
.get(link, (response) => {
response.pipe(file)
file.on("finish", () => {
file.close()
console.log(`Image downloaded as ${imageName}`)
});
})
.on("error", (err) => {
fs.unlink(imageName)
console.error(`Error downloading image: ${err.message}`)
});
});
await browser.close();
})();
//addons/tempbases/thumbs/1036/1286388805-1731.jpg
//foto/1036/1286388805-1731.jpg