我试图使用jsoup将URL (表:- contents)的内容抓取到数组中。到目前为止,在网上搜索类似于我的问题时,已经走到了死胡同。也许一双新的眼睛会有帮助。这是到目前为止我还没有看到的东西,我在某个地方读到我需要识别表id,然后使用元素循环遍历每一行的标记,如果是这样的话?
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站点的输出源(相关部分) :-
<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国家:美国类型:透明.
有什么帮助吗?
发布于 2015-10-09 12:56:03
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();
}
}
https://stackoverflow.com/questions/33038770
复制相似问题