【问题标题】:cheerio not picking up particular elementsCheerio 没有选择特定的元素
【发布时间】:2021-11-07 20:04:55
【问题描述】:

您好,尝试使用cheerio 抓取此https://davesgarden.com/guides/pf/finder/index.php?sname=Hibiscus&page=1,并且可以访问一些元素,例如菜单项,但不能访问我需要的植物名称。我使用此代码尝试获取植物名称

const $ = cheerio.load(data);

$('#contAfterAds > div > div.plant-info > div > a').each((_idx, el) => {
            const postTitle = $(el).text()
            postTitles.push(postTitle)
        });

但没有运气,有什么建议吗?看到角位不能被刮掉,会不会是类似的问题?

【问题讨论】:

    标签: javascript web-scraping jquery-selectors cheerio


    【解决方案1】:

    这是一个兄弟姐妹:

    $(el).next().text()
    

    或者可能:

    $(el).next().next().text()
    

    【讨论】:

    • codepen.io/itsvetobaby/pen/oNweGOg,似乎都不起作用:/
    • 您之前在迭代 a,而 codepen 正在迭代 h2
    • 抱歉,笔写错了,它仍然无法工作。如果你能再快速浏览一下,那真的对我有帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-02
    • 2018-10-08
    • 1970-01-01
    • 2022-01-13
    • 2019-06-10
    相关资源
    最近更新 更多