public void crawlingData(){
String url = "http://……";
HttpClientBuilder hcb = HttpClientBuilder.create();
CloseableHttpClient hc = hcb.build();
HttpUriRequest get = new HttpGet(url);
CloseableHttpResponse responseCode;
try {
responseCode = hc.execute(get);
HttpEntity dataEnt = responseCode.getEntity();
String htmlString = EntityUtils.toString(dataEnt,"utf-8");
Document htmlDocument = Jsoup.parse(htmlString);
Elements elements = htmlDocument.getElementsByTag("tr");
//获取迭代器
Iterator it = elements.iterator();
while(it.hasNext()) {
Element element = (Element)it.next();
Node titleNode= element.child(0).childNode(0);
//遍历中。。。。。。
}
} catch (ClientProtocolException e) {
System.out.println("详情页网络连接出错:"+url);
e.printStackTrace();
} catch (IOException e) {
System.out.println("访问详情页出错:"+url);
e.printStackTrace();
}
}
jsoup-Elements的遍历(使用Iterator迭代器)
最新推荐文章于 2024-10-27 14:22:38 发布