[英]Get HTML tag using Jsoup
Please search and post code in the future, it took me a few seconds to find an appropriate set of answers for this question. 以后请搜索并发布代码,我花了几秒钟时间才找到该问题的适当答案。
Sources: 资料来源:
http://jsoup.org/cookbook/input/load-document-from-url http://jsoup.org/cookbook/input/load-document-from-url
Document doc = Jsoup.connect("http://example.com/").get(); Elements elements = doc.body().select("item"); for (Element element : elements) { System.out.println(element.ownText()); }
I (...) need to iterate through item tags in the document, but I cannot find the tag.
我(...)需要遍历文档中的项目标签,但是找不到标签。
There's no tag item
. 没有标签
item
。 Instead it's a div
element with s-item-container
class. 相反,它是带有
s-item-container
类的div
元素。
Document doc = Jsoup //
.connect("http://www.amazon.com/s/ref=nb_sb_ss_i_1_4?url=search-alias%3Daps&field-keywords=clash+royale&sprefix=clas%2Caps%2C288&rh=i%3Aaps%2Ck%3Aclash+royale") //
.get();
for (Element item : doc.select("div.s-item-container")) {
System.out.println("-----");
System.out.println("Title: " + item.select("a.s-access-detail-page").attr("title"));
System.out.println("Customer Reviews Count: " + item.select("a[href$=#customerReviews]").text());
// Extract other data...
}
-----
Title:
Customer Reviews Count:
-----
Title: Impact ryale
Customer Reviews Count: 1
-----
Title: Castle Clash: Age of Legends
Customer Reviews Count: 6,001
-----
Title: Geometry Dash Meltdown
Customer Reviews Count: 2,924
(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.