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