简体   繁体   中英

Get HTML tag using Jsoup

I am using Jsoup to get Amazon item data from a URL and need to iterate through item tags in the document, but I cannot find the tag.

An example URL can be found here . What am I doing wrong?

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:

I (...) need to iterate through item tags in the document, but I cannot find the tag.

There's no tag item . Instead it's a div element with s-item-container class.

SAMPLE CODE

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...
}

OUTPUT (stripped)

-----
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
(...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM