Path: blob/master/node_modules/@bochilteam/scraper/lib/esm/social-media/google-it.js
1126 views
import cheerio from 'cheerio';1import got from 'got';2export async function googleIt(query) {3const body = await got('https://www.google.com/search', {4searchParams: {5q: query6},7headers: {8'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'9}10}).text();11const $ = cheerio.load(body);12const infoEl = $('div.I6TXqe > div.osrp-blk');13const info = {14title: infoEl.find('h2.qrShPb > span').text().trim(),15type: infoEl.find('div.SPZz6b > div.wwUB2c > span').text().trim(),16description: '',17image: []18};19infoEl20.find('div.LuVEUc > div.UDZeY > div.wDYxhc[data-attrid]:not(.NFQFxe)')21.each(function () {22const desc = $(this).text().trim();23if (desc)24info.description += desc + '\n';25});26infoEl27.find('div[jscontroller=M0hWhd] > div[jscontroller=ABJeBb] > div.eA0Zlc[jsname=dTDiAc]')28.each(function () {29var _a, _b;30const img = (_a = $(this)31.find('a > g-img.BA0A6c > img.rISBZc')32.attr('src')) === null || _a === void 0 ? void 0 : _a.trim(); // you can make buffer using function fromBase64ToString33if (img)34(_b = info.image) === null || _b === void 0 ? void 0 : _b.push(img);35});36info.image = [...new Set(info.image)];37const articles = [];38$('div.tF2Cxc').each(function () {39const el = $(this);40const header = el.find('cite.iUh30').text();41const title = el.find('div.yuRUbf > a > h3').text();42const url = el.find('div.yuRUbf > a[href]').attr('href');43const description = el.find('div.VwiC3b > span').text() || el.find('div.VwiC3b').text();44if (el.length && url) {45articles.push({46header: header,47title: title,48url,49description: description50});51}52});53return {54info,55articles56};57}58//# sourceMappingURL=google-it.js.map5960