首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用jsoup获取表的内容

使用jsoup获取表的内容
EN

Stack Overflow用户
提问于 2015-10-09 12:50:32
回答 1查看 2.3K关注 0票数 1

我试图使用jsoup将URL (表:- contents)的内容抓取到数组中。到目前为止,在网上搜索类似于我的问题时,已经走到了死胡同。也许一双新的眼睛会有帮助。这是到目前为止我还没有看到的东西,我在某个地方读到我需要识别表id,然后使用元素循环遍历每一行的标记,如果是这样的话?

代码语言:javascript
运行
复制
try {               
    Document doc = Jsoup.connect("http://www.us-proxy.org").userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36").get();
    //utilize the fetched html    
} catch(Exception e{  
    e.printStackTrace();   
} 

这是我的URL html站点的输出源(相关部分) :-

代码语言:javascript
运行
复制
<table cellpadding="0" cellspacing="0" border="0" class="display fpltable" id="proxylisttable">
  <thead>
    <tr>
      <th>IP Address</th>
      <th>Port</th>
      <th>Code</th>
      <th>Country</th>
      <th>Anonymity</th>
      <th>Google</th>
      <th>Https</th>
      <th>Last Checked</th>
    </tr>
  </thead>
  <tbody>
    <tr><td>24.210.34.226</td><td>3128</td><td>US</td><td>United States</td><td>transparent</td><td>no</td><td>no</td><td>18 hours 20 minutes ago</td></tr>
    <tr><td>50.76.49.97</td><td>4444</td><td>US</td><td>United States</td><td>transparent</td><td>no</td><td>no</td><td>18 hours 20 minutes ago</td></tr>
    <tr><td>
  </tbody>
  <tfoot>
    <tr>
      <th class="input"><input type="text" /></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </tfoot>
</table>

我想要的输出应该类似于这个代理: 50.76.49.97端口:4444国家:美国类型:透明.

有什么帮助吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-09 12:56:03

代码语言:javascript
运行
复制
    Elements elements = doc.select("table[class=display fpltable]");

    Elements rows = elements.get(0).select("tr");

    for (Element row : rows) {

        if (row.select("td").size() == 8) {
            String iPAddress = row.select("td").get(0).text();
            String port = row.select("td").get(1).text();
            String code = row.select("td").get(2).text();
            String country = row.select("td").get(3).text();
            String anonymity = row.select("td").get(4).text();
            String google = row.select("td").get(5).text();
            String https = row.select("td").get(6).text();
            String lastChecked = row.select("td").get(7).text();
        }

    }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33038770

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档