gpt4 book ai didi

java - 我如何使用java中的html解析器从DIV中获取数据

转载 作者:行者123 更新时间:2023-12-01 15:58:28 25 4
gpt4 key购买 nike

我正在使用Java html解析器(link text)来尝试解析这一行。

<td class=t01 align=right><div id="OBJ123" name=""></div></td>

但我正在寻找像我在网络浏览器上看到的那样的值,这是一个数字。你能帮我得到这个值吗?

如果您需要更多详细信息,请告诉我。
谢谢

最佳答案

从文档中,您所要做的就是找到所有 DIV id 也为 OBJ123 的元素并取第一个结果的值。

NodeList nl = parser.parse(null); // you can also filter here

NodeList divs = nl.extractAllNodesThatMatch(
new AndFilter(new TagNameFilter("DIV"),
new HasAttributeFilter("id", "OBJ123")));

if( divs.size() > 0 ) {
Tag div = divs.elementAt(0);
String text = div.getText(); // this is the text of the div
}

更新:如果您正在查看ajax url ,您可以使用类似的代码,例如:

// make some sort of constants for all the positions
const int OPEN_PRICE = 0;
const int HIGH_PRICE = 1;
const int LOW_PRICE = 2;
// ....

NodeList nl = parser.parse(null); // you can also filter here

NodeList values = nl.extractAllNodesThatMatch(
new AndFilter(new TagNameFilter("TD"),
new HasAttributeFilter("class", "t1")));

if( values.size() > 0 ) {
Tag openPrice = values.elementAt(OPEN_PRICE);
String openPriceValue = openPrice.getText(); // this is the text of the div
}

关于java - 我如何使用java中的html解析器从DIV中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4527672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com