ben ben - 3 years ago 95
HTML Question

How can I retrieve data from html using Jsoup

I'm new to HTML and I'm trying to learn a little about the HTML tags by trying to retrieve data from an HTML String.

<div class="item" data-youtube_code="code_for_youtuber" data-feature_code="data" data-feature_url="/movies/Truman">
<div class="title">
<span>the title of the video</span>
<div class="image">
<img src="/media/image.png" data-src="http://url_of_image.jpg" alt="">
</div> </li>

I'm using the Java Jsoup library and so far I've manage to extract the
content using:

Document doc = Jsoup.connect("").get();
Elements elem =".item").text();

How can I get other things such as the
and the
img src

For example:

System.out.println("");//some code that retrieves
//data-youtube_code. The ouptup will be "code_for_youtuber"

//some code that retrieves
//data-src. The ouptup will be "http://url_of_image.jpg"

Answer Source

You can simply select first div and get the value by attribute

    Element elements = Jsoup.parse(s).select("div").first();



Since you are beginner i suggest you to look for this link

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download