Reputation: 377
I have an online shop from which I need to get a set of products with specific parameters like name, price, description and so on after I search some kind of projects. Search is performed through keyword input. Here is a website: https://www.aboutyou.de/dein-shop. And this is the search I was trying to parse: https://www.aboutyou.de/frauen/accessoires/huete-und-muetzen/caps?pl=1
So I need to get all this data considering that in html source of the page there is a complex hierarchy of tags. I tried to get my elements by classes, except the highest one which is marked by the id and wrapped by the body. So I tried to do something like this using jsoup:
lements resultt = doc.body().select("main#app");
for(Element el : resultt){
Elements main = el.getElementsByClass("section.layout_11glwo1-o_O-stretchLayout_1jug6qr > " +
"div.content_1jug6qr > " +
"div.container > " +
"div.mainContent_10ejhcu > " +
"div.productStream_6k751k > " +
"div > " +
"div.wrapper_8yay2a > " +
"div.col-sm-6.col-md-4 > " +
"div.wrapper_1eu800j > " +
"div > " +
"div.categoryTileWrapper_e296pg > " +
"a.anchor_wgmchy > " +
"div.details_197iil9 > " +
"div.meta_1ihynio > " +
"div.finalPrice_11ythok > " +
"span.price_1543wg1");
System.out.println("just print it" + main.text());
}
But nothing is printed after "just print it" phrase. I know it is not a configuration problem as I tied to gem some information using higher level tags. What can I cahnge in my code to get this products entities information? I am new to jsoup so I would be grateful for any help!
Upvotes: 0
Views: 150
Reputation: 6151
If you replace Elements main = el.getElementsByClass("section.layout_11glwo1-o_O-stretchLayout_1jug6qr >...
with el.select
you get a list of all prices:
17,90€ 19,90€ 19,90€ 24,90€ 19,90€ 24,90€ 24,90€ 19,90€ 17,90€ 19,90€ 17,90€ 49,90€ 39,90€ 39,90€ 17,90€ 19,99€ 39,90€ 19,99€ 34,95€ 17,90€
That's probably because the selector is not a class selector.
EDIT this is the full code which works for me -
Document doc = Jsoup.connect("https://www.aboutyou.de/frauen/accessoires/huete-und-muetzen/caps?pl=1")
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0")
.get();
Elements result = doc.body().select("main#app");
for(Element el : result) {
Elements e = el.select("section.layout_11glwo1-o_O-stretchLayout_1jug6qr > " +
"div.content_1jug6qr > " +
"div.container > " +
"div.mainContent_10ejhcu > " +
"div.productStream_6k751k > " +
"div > " +
"div.wrapper_8yay2a > " +
"div.col-sm-6.col-md-4 > " +
"div.wrapper_1eu800j > " +
"div > " +
"div.categoryTileWrapper_e296pg > " +
"a.anchor_wgmchy > " +
"div.details_197iil9 > " +
"div.meta_1ihynio > " +
"div.finalPrice_11ythok > " +
"span.price_1543wg1");
System.out.println(e.text());
}
Upvotes: 1