2

I am stuck at a place where I need to parse this website and display the Top PlayStation 3 Games by Metascore with their ratings. I am not able to come up with good parsing using JSoup as I just started developing using Jsoup.

I got the ratings and title like this. Any better ways ?

Document doc = Jsoup.connect(URL).userAgent("Mozilla").get();
// To get score
Elements links = doc.select("span.metascore_w.medium.game");
// To get title
Elements links = doc.select("h3.product_title");
      for (Element link : links) {
        System.out.println("text : " + link.text());
      }
1
  • 1
    You can post your attempt at it to get a quicker resolution Commented Jan 30, 2014 at 18:38

2 Answers 2

2

The other way you can look at is look for a repetitive parent for both the tags (like div.main_stats) you need and iterate over it gathering the elements:

Elements parents = doc.select("div.main_stats");
for (Element child : parents) {
    Element label = child.select("h3.product_title").first();
    Element score = child.select("span.metascore_w.medium.game").first();
System.out.println("Game **" + label.text()+ "** has a Metascore of ->> " + score.text());

}

Output:

Game **XCOM: Enemy Within** has a Metascore of ->> 88
Game **Minecraft: PlayStation 3 Edition** has a Metascore of ->> 86
Game **Gran Turismo 6** has a Metascore of ->> 81
Game **Need for Speed: Rivals** has a Metascore of ->> 80
Sign up to request clarification or add additional context in comments.

Comments

0

I came up with this code :

Element div = doc.select("ol.list_products.list_product_summaries").first(); 
      for (Element element : div.children()) {
        System.out.println(element.select("span.metascore_w.medium.game").text());
        System.out.println(element.select("h3.product_title").text());
      }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.