Home » Java » java – Parsing a specific element using JSoup-Exceptionshub

java – Parsing a specific element using JSoup-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment


I’m wondering if anyone is familiar with parsing a specific part of a website’s HTML, such as getting a current temperature or current conditions from a website using JSoup? I’ve searched all over and it seems like all the examples are people using for each loops to extract a list. For example in the picture I attached, I only want to parse the -3 degrees into my IDE. Any help would be greatly appreciated! Thanks!



How to&Answers:

You should be able to use standard selectors to get the data you want from the Document.select() method. The easiest way to get this would be to open the web page in your browser’s inspector, inspect that element specifically, then context-click its node in the element viewer and select Copy -> Selector Path.

Personally, I’ve experienced pretty substantial trouble with JSoup and have found that injecting artoo.js is usually a quicker way to get what I want out of a page regardless of environment.