-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selectable接口中xpath获取值的问题 #860
Comments
@code4craft 可以帮忙看下吗 |
我运行了一下你的代码, 有解析到数据啊,你的问题描述不是太清楚. |
selectable.xpath有获取到值吗不在debug模式下?page.xpath是获取得到的 |
@code4craft是有解析到数据,但是selectable.xpath和 page.getHtml().xpath的解析结果不一致,原则上是要一致的。selectable.xpath这个取到的值是由问题的,不是a[4]的值而是a[1]. |
是有解析到数据,但是selectable.xpath和 page.getHtml().xpath的解析结果不一致,原则上是要一致的。selectable.xpath这个取到的值是由问题的,不是a[4]的值而是a[1]. |
@newbiero 我也发生了下标取值错误问题
str的值不是list.get(2)的值,但如果取a[2]的值则与list.get(1)一致 |
check your code. |
@code4craft 作者您好,问个问题:
先用这个 List nodes = page.getHtml().xpath("").nodes();
在循环,然后Selectable selectable = nodes.get(i);再然后selectable.xpath("xxx")在debug模式下,打断点获取的值没有问题,但是直接运行就获取的有问题。这是为什么呢?
示例网址:http://www.atobo.com.cn/Companys/s-p6-k174255/
代码:
List nodes = page.getHtml().xpath("//div[@Class='product_contextlist bplist']/ul/li").nodes();
Selectable selectable = null;
for(int i = 0, len = nodes.size(); len > i; ++i) {
selectable = nodes.get(i);
System.out.println("selectable的xpath获取:" + selectable.xpath("//div/ul/li[@Class='p_name']/div/ul/li[contains(@Class,'pp_2web')]/a[4]/allText()").toString());
System.out.println("page的xpath获取:" + page.getHtml().xpath("//div[@Class='product_contextlist bplist']/ul/li[" + (i + 1) + "]/div/ul/li[@Class='p_name']/div/ul/li[contains(@Class,'pp_2web')]/a[4]/allText()").toString());
}
The text was updated successfully, but these errors were encountered: