mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-13 00:35:19 +08:00
* fix(route): 修复 米游社 公告栏 template 错误 * feat(route): 新增 bing 搜索 * docs: Update other.mdx * docs: fix docs * feat(route): 新增 百度搜索 * fix(route): 修复 pubDate 解析错误 * fix(route): 优化 百度搜索的缓存,减轻反爬问题 * feat(route): 新增 360 搜索 * feat(route): 迁移 搜狗特色LOGO 到 v2 规范;添加 搜狗搜索 * fix(route): 百度搜索增加图片 * feat(route): 新增 Google Search * fix(route): 修复 百度搜索相关问题 * fix(route): 修复 Google 相关问题 * fix(route): 修复 360 搜索 * fix(route): 修复 搜狗搜索 * fix(route): 修复 await 问题 * fix: 移除 google sites * fix(route): 修复 缓存和过滤逻辑问题 * fix(route): 修复 360 搜索缺少 cookie 的问题 * fix(route): 修复 360 搜索 cookie 的问题 * feat(route): 移除 so.com 路由 * fix: merge conflict ---------
63 lines
2.4 KiB
JavaScript
63 lines
2.4 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const { art } = require('@/utils/render');
|
|
const path = require('path');
|
|
const config = require('@/config').value;
|
|
|
|
const renderDescription = (description, images) => art(path.join(__dirname, './templates/description.art'), { description, images });
|
|
|
|
module.exports = async (ctx) => {
|
|
const { keyword, language } = ctx.params;
|
|
const searchParams = new URLSearchParams({
|
|
q: keyword,
|
|
});
|
|
const tempUrl = new URL('https://www.google.com/search');
|
|
tempUrl.search = searchParams.toString();
|
|
const url = tempUrl.toString();
|
|
const key = `google-search:${language}:${url}`;
|
|
const items = await ctx.cache.tryGet(
|
|
key,
|
|
async () => {
|
|
const response = (
|
|
await got(url, {
|
|
headers: {
|
|
'Accept-Language': language,
|
|
},
|
|
})
|
|
).data;
|
|
const $ = cheerio.load(response);
|
|
const content = $('#rso');
|
|
return content
|
|
.find('> div')
|
|
.map((i, el) => {
|
|
const element = $(el);
|
|
const link = element.find('div > div > div > div > div > span > a').first().attr('href');
|
|
const title = element.find('div > div > div> div > div > span > a > h3').first().text();
|
|
const imgs = element
|
|
.find('img')
|
|
.map((_j, _el) => $(_el).attr('src'))
|
|
.toArray();
|
|
const description = element.find('div[style="-webkit-line-clamp:2"]').first().text() || element.find('div[role="heading"]').first().text();
|
|
const author = element.find('div > div > div > div > div > span > a > div > div > span').first().text() || '';
|
|
return {
|
|
link,
|
|
title,
|
|
description: renderDescription(description, imgs),
|
|
author,
|
|
};
|
|
})
|
|
.toArray()
|
|
.filter((e) => e?.link);
|
|
},
|
|
config.cache.routeExpire,
|
|
false
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: `${keyword} - Google Search`,
|
|
description: `${keyword} - Google Search`,
|
|
link: url,
|
|
item: items,
|
|
};
|
|
};
|