如何获取网站的中间值(Web Scraping)

How to get the middle value off a website (Web Scraping)

有三个 类 称为 gauge-value 我想得到第二个,但它没有输出任何东西。我正在这个网站上做网络抓取 https://stockx.com/supreme-hot-wheels-fleet-flyer-1992-bmw-m3-red here is the area that I'm trying to get the middle value out of http://prntscr.com/nfk6x8 我认为让 porText = porHeading.first().next().text();会工作但没有。

我已经试过第一个和最后一个(都有效) 让 porText = porHeading.first().text(); 让 porText = porHeading.last().text();

        ///Check the site like to find gauge-value
        const porHeading = $(".gauge-value");
        let porText = porHeading.first().next().text();

        ///Trying to log number
        console.log(porText);

        ///Removing percent
        porText = porText.replace("%","");

        ///Final Value
        console.log('-----');
        console.log(porText);
        console.log('-----');

当我 运行 程序是空白但当我执行 .first() 或 .最后()它工作正常。 -感谢您的帮助,Nate

您可以使用这个选择器:

document.querySelector("div.gauges > div:nth-child(2) > div.gauge-value").textContent; //213.3%

您也可以执行 .eq() jQuery 功能。

let porText = porHeading.eq(1).text();

HTH!