user2923535 user2923535 - 1 year ago 94
Java Question

JSoup extracting class title

I'm trying to pull some data from this link:

What I'm specifically looking for is for every link-image text. IE from this section:

<div class="seasonal-anime js-seasonal-anime"
<div class="title"><a href="" class="icon-watch-pv fl-r" title="Watch Promotional Video">Watch Promotional Video</a><p class="title-text">
<a href="" class="link-title">Bungou Stray Dogs 2nd Season</a>

<div class="prodsrc">
<span class="producer"><a href="/anime/producer/4/Bones" title="Bones">Bones</a></span>
<div class="eps">
<span id="32867" data-eps="12" class="fl-l icon-add-episode js-btn-add-episode" title="Click to increase your watched ep number by one"></span> <a href=""><span class="js-episode-num">6</span>/<span>12 eps</span>

<span class="source">Manga</span>

<a href="" title="Watching" class="Lightbox_AddEdit button_edit btn-anime-watch-status js-anime-watch-status watching">CW</a>

<div class="genres js-genre" id="32867">
<div class="genres-inner js-genre-inner"><span class="genre">
<a href="/anime/genre/7/Mystery" title="Mystery">Mystery</a>
</span><span class="genre">
<a href="/anime/genre/42/Seinen" title="Seinen">Seinen</a>
</span><span class="genre">
<a href="/anime/genre/37/Supernatural" title="Supernatural">Supernatural</a>

<div class="image lazyload" data-bg="">
<a href="" class="link-image">Bungou Stray Dogs 2nd Season</a>

<div class="synopsis js-synopsis">
<span class="preline">Nakajima Atsushi was kicked out of his orphanage, and now he has no place to go and no food. While he is standing by a river, on the brink of starvation, he rescues a man whimsically attempting suicide. That man is Dazai Osamu, and he and his partner Kunikida are members of a very special detective agency. They have supernatural powers and deal with cases that are too dangerous for the police or the military. They&#039;re tracking down a tiger that has appeared in the area recently, around the time Atsushi came to the area. The tiger seems to have a connection to Atsushi, and by the time the case is solved, it is clear that Atsushi&#039;s future will involve much more of Dazai and the rest of the detectives!

(Source: MangaHelpers)</span>
<p class="licensors" data-licensors=""></p>

<div class="information">
<div class="info">
TV -
<span class="remain-time">
Oct 6, 2016, 22:30 (JST) </span>
<div class="scormem">
<span class="member fl-r" title="Members">
<span class="score" title="Score">


I want to get the text Bungou Stray Dogs 2nd Season. I'd also like to get the data-bg value( and also get the score(8.34) but for every pair of this data.

I'm not really sure what query to run with Jsoup as I'm very new to HTML still and don't really understand it.

Running this code doesn't get me anything:

Document doc = Jsoup.connect("").get();
Elements shows ="div:contains(image.lazyload)");

int i = 0;
for(Element show : shows){
System.out.println(i+". "+show.text());

Answer Source

You just need to follow the select syntax as documented here.

For example, to get the link-image text:

Elements imageLinks ="");

The other two are similar. I'm sure you can figure that out.

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