[英]How to parse a html table data through table id using JSoup in java
我需要将客户端的表数据存储到数据库中。
有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" ]
如果有一个Table Class,显然我可以很容易地解析它,但是没有类只是id在表中给出。
我知道只有一个单词的语法,除了
for (Element table : doc.select("table")
也许我找不到它。 怎么找到它? 我试过了
for (Element table : doc.select("table.AutoNumber5")
但这对我不起作用。
如何解决这个问题?
试试这个
doc.select("table#AutoNumber5");
它对我有用。
参考: http : //jsoup.org/apidocs/org/jsoup/select/Selector.html
jsoup支持css选择器,如果你知道css它很容易使用,如下所示:
Document doc = Jsoup.connect(“ http://xxxxxxxx.com/ ”)。get();
元素el = doc.select(“#targeted-elemnet-id”);
你只需要在没有空格的#符号后替换你的元素id。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.