从 /r/GameDeals 抓取 discord.js 中包含单词 'FREE' 的标题和链接?

Scraping titles + links from /r/GameDeals that contain the word 'FREE' in discord.js?

我是 Javascript 和一般编程的超级新手,我在 Discord 频道找到了一个可以练习它和 share/create 功能的渠道,供我和我的朋友使用。我正在尝试设置一个抓取器,从 /r/GameDeals subreddit 中提取带有包含单词 'Free' 的链接的标题。到目前为止,通过我在网上找到的资源,我已经能够获得前 25 个链接:

const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch();
    const [page] = await browser.pages();

    await page.goto('https://www.reddit.com/r/GameDeals/', { waitUntil: 'networkidle0' });
    const links = await page.evaluate(async () => {
        window.scrollBy(0, document.body.clientHeight);
        await new Promise(resolve => setTimeout(resolve, 1)); 
        return [...document.querySelectorAll('.scrollerItem div:nth-of-type(2) article div div:nth-of-type(3) a')]
            .map((el) => el.href);
    });
    bot.on('message', msg=>{
        if(msg.content === "gamedeals"){
            msg.reply(links, links.length);
            }
        })

    await browser.close();
})(); 

我对 HTML 类 我需要具体说明什么才能得到我需要的东西的理解非常有限,添加“包含单词:免费”的过滤器完全是另一回事.

任何指导将不胜感激。

我正在使用 puppeteer,但有人建议我通过使用 'reddit.com/r/GameDeals.json' 尝试使用 Reddit 的 JSON API,但我不确定如何开始。

如果您只想查找包含单词“免费”的链接,则需要过滤您在 page.evaluate:

中获得的节点
[...document.querySelectorAll('.scrollerItem div:nth-of-type(2) article div div:nth-of-type(3) a')] // <-- we've got all the links
  .filter((el) => el.innerText.toLowerCase().includes('free') ) // <-- only keep those with word "free"
  .map((el) => el.href);