简体   繁体   English

Jsoup对特定表数据

[英]Jsoup on specific table data

First of all, I'm sorry of the erotic content of the page but look past it , it's not about the page itself. 首先,对页面的色情内容感到抱歉,但请看过去,它与页面本身无关。

I'm trying to get the price of something from this page: JSFiddle 我正在尝试从此页面获取价格: JSFiddle

On row 67 it says "Adviesprijs:", I need the value in the next td after that, without the btw stuff (which is Belgian tax if you're wondering) 在第67行上显示“ Adviesprijs:”,此后我需要下一个td的值,没有btw的东西(如果您想知道的话,这是比利时税)

For example: "19.95" as a String 例如:“ 19.95”作为字符串

How do I get this content using JSoup? 如何使用JSoup获得此内容?

This is what I have so far : 这是我到目前为止所拥有的:

Element element = doc.getElementById("productdetails");

if (element.text().contains("Adviesprijs:")) { 
   String price = element.parent().ownText(); 
   System.out.println(price); 
} 

It doesn't work though. 虽然不行。

you better use a selector for this: 您最好为此使用选择器

/* select all tags with "Adviesprijs:" text */
Elements result = doc.select("*:containsOwn(Adviesprijs:)");

/* iterate over all elements found */
for( Element e : result )
{
    String key = e.text(); /* "Adviesprijs:" */
    String value = e.nextElementSibling().text(); /* text of next element */

    System.out.println(key + "\t" + value);
}

prints: Adviesprijs: € 19,95 (incl. 21% btw) 印刷品: Adviesprijs: € 19,95 (incl. 21% btw)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM