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