Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从网站中获取中间值(网页抓取)_Javascript_Node.js_Discord.js_Cheerio - Fatal编程技术网

Javascript 如何从网站中获取中间值(网页抓取)

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.

有三个类叫做gauge value,我想得到第二个,但它没有输出任何东西。我在这个网站上做网页抓取,这里是我试图从中得到中间值的区域,我想让porText=portheading.first().next().text();它会起作用,但没有

我已经试着得到第一个和最后一个(都有效) 让porText=portheading.first().text(); 让porText=portheading.last().text()

当我运行程序时,我想得到没有中间量表值文本百分比的数字(应该是213.3%左右),它是空的,但当我运行.first()或.last()时,它工作正常。
-感谢您的帮助,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();