UNPKG

rsshub

Version:
66 lines (62 loc) 3.07 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import "./ofetch-DKl_Ma9g.mjs"; import "./helpers-Bo4JQYdN.mjs"; import { t as got_default } from "./got-CO-ndVl2.mjs"; import { load } from "cheerio"; //#region lib/routes/google/scholar.ts const route = { path: "/scholar/:query", categories: ["journal"], example: "/google/scholar/data+visualization", parameters: { query: "query statement which supports「Basic」and「Advanced」modes" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: true, supportBT: false, supportPodcast: false, supportScihub: false }, name: "Scholar Keywords Monitoring", maintainers: ["HenryQW"], handler, description: `::: warning Google Scholar has strict anti-crawling mechanism implemented, the demo below doesn't guarantee availability. Please deploy your own instance as it might increase the stability. ::: 1. Basic mode, sample query is the keywords desired, eg.「data visualization」, [https://rsshub.app/google/scholar/data+visualization](https://rsshub.app/google/scholar/data+visualization). 2. Advanced mode, visit [Google Scholar](https://scholar.google.com/schhp?hl=en&as_sdt=0,5), click the top left corner and select「Advanced Search」, fill in your conditions and submit the search. The URL should look like this: [https://scholar.google.com/scholar?as_q=data+visualization&as_epq=&as_oq=&as_eq=&as_occt=any&as_sauthors=&as_publication=&as_ylo=2018&as_yhi=&hl=en&as_sdt=0%2C5](https://scholar.google.com/scholar?as_q=data+visualization&as_epq=&as_oq=&as_eq=&as_occt=any&as_sauthors=&as_publication=&as_ylo=2018&as_yhi=&hl=en&as_sdt=0%2C5), copy everything after \`https://scholar.google.com/scholar?\` from the URL and use it as the query for this route. The complete URL for the above example should look like this: [https://rsshub.app/google/scholar/as_q=data+visualization&as_epq=&as_oq=&as_eq=&as_occt=any&as_sauthors=&as_publication=&as_ylo=2018&as_yhi=&hl=en&as_sdt=0%2C5](https://rsshub.app/google/scholar/as_q=data+visualization&as_epq=&as_oq=&as_eq=&as_occt=any&as_sauthors=&as_publication=&as_ylo=2018&as_yhi=&hl=en&as_sdt=0%2C5).` }; async function handler(ctx) { let params = ctx.req.param("query"); let query = params; let description = `Google Scholar Monitor Query: ${query}`; if (params.includes("as_q=")) { query = /as_q=(.*?)&/g.exec(params)[1]; description = `Google Scholar Monitor Advanced Query: ${query}`; } else params = "q=" + params; const url = `https://scholar.google.com/scholar?${params}`; const out = load((await got_default({ method: "get", url })).data)("#gs_res_ccl_mid .gs_r.gs_or.gs_scl .gs_ri").toArray().map((item) => { const $ = load(item); const itemUrl = $("h3 a").attr("href"); return { title: $("h3 a").text(), author: $(".gs_a").text(), description: $(".gs_rs").text(), link: itemUrl, guid: itemUrl }; }); return { title: `Google Scholar Monitor: ${query}`, link: url, description, item: out }; } //#endregion export { route };