如何使用 Cheerio 从 Google Scholar 获取标题的全文?

问题描述 投票:0回答:0

我正在使用 axios 在 google scholar 上发送获取请求。使用 cheerio 我可以访问数据。当标题太长时,我会得到:标题:“黄体期卵巢刺激与传统卵巢刺激体外受精和玻璃化胚胎移植后活产缺陷的比较……”。

这是代码:

await axios.get(`https://scholar.google.com/scholar?q=${searchTerm}`, proxy).then(async result => {

            const $ = cheerio.load(result.data);

            $('div.gs_ri').each((i, el) => {

              const yearElement = $(el).find('div.gs_a');
              const yearText = yearElement.text().match(/\d{4}/);
              const titleElement = $(el).find('h3.gs_rt a');

              scholar_results.push({
                title: titleElement.text().trim(),
                link: $(el).find(".gs_rt a").attr("href"),
                year: yearText ? parseInt(yearText[0]) : null
              })
            })

}

有没有办法获得完整的标题而不是截断的标题。

javascript node.js axios cheerio google-scholar
© www.soinside.com 2019 - 2024. All rights reserved.