[英]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.