Javascript 如何从网站中获取中间值(网页抓取)
有三个类叫做gauge value,我想得到第二个,但它没有输出任何东西。我在这个网站上做网页抓取,这里是我试图从中得到中间值的区域,我想让porText=portheading.first().next().text();它会起作用,但没有 我已经试着得到第一个和最后一个(都有效) 让porText=portheading.first().text(); 让porText=portheading.last().text() 当我运行程序时,我想得到没有中间量表值文本百分比的数字(应该是213.3%左右),它是空的,但当我运行.first()或.last()时,它工作正常。Javascript 如何从网站中获取中间值(网页抓取),javascript,node.js,discord.js,cheerio,Javascript,Node.js,Discord.js,Cheerio,有三个类叫做gauge value,我想得到第二个,但它没有输出任何东西。我在这个网站上做网页抓取,这里是我试图从中得到中间值的区域,我想让porText=portheading.first().next().text();它会起作用,但没有 我已经试着得到第一个和最后一个(都有效) 让porText=portheading.first().text(); 让porText=portheading.last().text() 当我运行程序时,我想得到没有中间量表值文本百分比的数字(应该是213.
-感谢您的帮助,Nate您可以使用此选择器:
document.querySelector("div.gauges > div:nth-child(2) > div.gauge-value").textContent; //213.3%
您也可以使用jQuery函数
let porText = porHeading.eq(1).text();
嗯 谢谢,效果很好。我有点困惑。eq()是做什么的,我查过了。你能简单地给我解释一下吗?谢谢将所有$(“.gauge value”)元素视为索引为0的数组。当您使用.eq(1)时,它基本上与使用objeelements[1]一样好,因此它使用与选择器匹配的第二个元素。很抱歉响应太晚,但感谢您,这将在将来有很大帮助:)
let porText = porHeading.eq(1).text();