-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheksi.js
74 lines (70 loc) · 2.8 KB
/
eksi.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
65
66
67
68
69
70
71
72
73
74
const puppeteer = require('puppeteer');
const fs = require('fs');
(async () => {
try {
const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] });
const page = await browser.newPage();
let sayfalar;
async function sayfaSayilari() {
const navigationPromise = page.waitForNavigation();
await page.goto('https://eksisozluk.com/mutluluk--40751', {waitUntil: 'networkidle0'});
await page.addScriptTag({url: 'https://code.jquery.com/jquery-3.4.1.min.js'});
await page.setViewport({ width: 1280, height: 721 })
await navigationPromise;
await page.waitFor(5000);
sayfalar = await page.evaluate(() => {
let data = [];
$($('.pager')[0]).find('select > option').each((ind, itm) => {
data.push($(itm).val());
});
return data;
});
}
async function sayfaCek(sayfaNo) {
console.log(`${sayfaNo} numaralı sayfa çekiliyor...`);
const navigationPromise = page.waitForNavigation();
await page.goto('https://eksisozluk.com/mutluluk--40751?p=' + sayfaNo, {waitUntil: 'networkidle0'});
await page.addScriptTag({url: 'https://code.jquery.com/jquery-3.4.1.min.js'});
await page.setViewport({ width: 1280, height: 721 })
await navigationPromise;
await page.waitFor(5000);
let entryler = [];
let donus = await page.evaluate(() => {
try {
let data = [];
const $ = window.$;
$('#entry-item-list > li').each((ind, item) => {
data.push($(item).find('.content').text().trim());
});
return data;
} catch (err) {
return err.toString();
}
});
entryler = entryler.concat(donus);
return entryler;
}
let tumEntry = [];
await sayfaSayilari();
if (sayfalar.length > 1) {
let args = process.argv.slice(2);
let sayfaNo = args[0] || 1;
while (sayfaNo <= sayfalar.length) {
tumEntry = await sayfaCek(sayfaNo);
let donus = [];
for (let e of tumEntry) {
donus.push({
intent: 'güzel',
language: 'tr',
utterance: e
});
}
fs.appendFileSync('güzel.json', JSON.stringify(donus));
sayfaNo++;
}
}
await browser.close();
} catch (err) {
console.log(err);
}
})();