【问题标题】:How to parse a html table data through table id using JSoup in java如何在java中使用JSoup通过表id解析html表数据
【发布时间】:2013-12-21 23:53:08
【问题描述】:

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

有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")

但这对我不起作用。

如何解决这个问题?

【问题讨论】:

    标签: java html-parsing jsoup html-parser


    【解决方案1】:

    试试这个

    doc.select("table#AutoNumber5");
    

    它对我有用。

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

    【讨论】:

      【解决方案2】:

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

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

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

      你只需要在#号后替换你的元素id,不带空格。

      【讨论】:

        猜你喜欢
        • 2019-06-04
        • 1970-01-01
        • 2018-11-19
        • 2017-07-15
        • 2015-10-14
        • 1970-01-01
        • 2011-07-20
        相关资源
        最近更新 更多