Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@bochilteam/scraper/lib/esm/social-media/google-it.js
1126 views
1
import cheerio from 'cheerio';
2
import got from 'got';
3
export async function googleIt(query) {
4
const body = await got('https://www.google.com/search', {
5
searchParams: {
6
q: query
7
},
8
headers: {
9
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
10
}
11
}).text();
12
const $ = cheerio.load(body);
13
const infoEl = $('div.I6TXqe > div.osrp-blk');
14
const info = {
15
title: infoEl.find('h2.qrShPb > span').text().trim(),
16
type: infoEl.find('div.SPZz6b > div.wwUB2c > span').text().trim(),
17
description: '',
18
image: []
19
};
20
infoEl
21
.find('div.LuVEUc > div.UDZeY > div.wDYxhc[data-attrid]:not(.NFQFxe)')
22
.each(function () {
23
const desc = $(this).text().trim();
24
if (desc)
25
info.description += desc + '\n';
26
});
27
infoEl
28
.find('div[jscontroller=M0hWhd] > div[jscontroller=ABJeBb] > div.eA0Zlc[jsname=dTDiAc]')
29
.each(function () {
30
var _a, _b;
31
const img = (_a = $(this)
32
.find('a > g-img.BA0A6c > img.rISBZc')
33
.attr('src')) === null || _a === void 0 ? void 0 : _a.trim(); // you can make buffer using function fromBase64ToString
34
if (img)
35
(_b = info.image) === null || _b === void 0 ? void 0 : _b.push(img);
36
});
37
info.image = [...new Set(info.image)];
38
const articles = [];
39
$('div.tF2Cxc').each(function () {
40
const el = $(this);
41
const header = el.find('cite.iUh30').text();
42
const title = el.find('div.yuRUbf > a > h3').text();
43
const url = el.find('div.yuRUbf > a[href]').attr('href');
44
const description = el.find('div.VwiC3b > span').text() || el.find('div.VwiC3b').text();
45
if (el.length && url) {
46
articles.push({
47
header: header,
48
title: title,
49
url,
50
description: description
51
});
52
}
53
});
54
return {
55
info,
56
articles
57
};
58
}
59
//# sourceMappingURL=google-it.js.map
60