首页 > 解决方案 > Cheerio 网页抓取 ul > li 属性

问题描述

我想从这个 url 中刮掉“数据价格”,但它回来了未定义。有任何想法吗?

https://i.stack.imgur.com/N9gei.png

async function variant() {
    const response = await axios("https://extrabutterny.com/collections/release-draws/products/nike-sb-dunk-low-pro-blue-fury-bq6817-400?variant=31800767021104");   
    console.log("response: ", response);
    const html = await response.data;
    const $ = cheerio.load(html);
    const id = $(".DrawApp-SizeChartList > li").attr("data-price");
    console.log(id);
}

标签: node.jsweb-scrapingrequestcheerioweb-scraping-language

解决方案


我知道您已经接受了答案,但如果您使用https://github.com/whatsdis/web-scraping-language

然后你可以编写 WSL,它也可以渲染 javascript 页面,你可以使用 Xpath:

GOTO https://extrabutterny.com/collections/release-draws/products/nike-sb-dunk-low-pro-blue-fury-bq6817-400?variant=31800767021104

EXTRACT {'price':'*[@class="DrawApp-SizeChartList"]/li/@data-price'}

推荐阅读