4

我需要将客户的表数据存储到数据库中。

有 n 个表没有提供任何表类(直接使用网页中的 Table_id)。

例子:

[table width="100%" border="0" cellpadding="0" cellspacing="0"  id="AutoNumber5" style="border-collapse: collapse" bordercolor="#111111"]<br/>
[table width="100%" border="0" cellpadding="0" cellspacing="0"  id="AutoNumber4" style="border-collapse: collapse" bordercolor="#111111" ]

如果有一个表类,显然我可以很容易地解析它,但是没有类只是在表中给出了 id。

我知道只有一个单词语法,除了

for (Element table : doc.select("table") 

也许我找不到它。如何找到它?我努力了

for (Element table : doc.select("table.AutoNumber5")

但这对我不起作用。

如何解决这个问题?

4

2 回答 2

3

jsoup 支持 css 选择器,如果你知道 css,它很容易像这样使用:

文档 doc = Jsoup.connect(" http://xxxxxxxx.com/ ").get();

元素 el = doc.select("#targeted-elemnet-id");

您只需要在 # 符号之后替换您的元素 ID,无需空格。

于 2013-12-05T07:15:42.583 回答
3

尝试这个

doc.select("table#AutoNumber5");

它对我有用。

参考:http: //jsoup.org/apidocs/org/jsoup/select/Selector.html

于 2013-12-05T07:36:10.780 回答