J.Doe
J.Doe

Reputation: 23

Grabbing information from an html file

OK, I am trying to grab the data-title and href and assigning them to variables in java.

<tr class="pl-video yt-uix-tile " data-video-id="MBBWVgE0ewk" data-set-video-id="" data-title="Windows Command Line Tutorial - 1 - Introduction to the Command Prompt"><td class="pl-video-handle "></td><td class="pl-video-index"></td><td class="pl-video-thumbnail"><span class="pl-video-thumb ux-thumb-wrap contains-addto"><a href="/watch?v=MBBWVgE0ewk&amp;index=1&amp;list=PL6gx4Cwl9DGDV6SnbINlVUd0o2xT4JbMu"

Upvotes: 0

Views: 66

Answers (1)

Alex Derkach
Alex Derkach

Reputation: 759

If you don't mind including a dependency, there is a good library for this kind of things called jsoup.

String html = ...
Document doc = Jsoup.parse(html);

Element tr = doc.select("tr").first();
Element link = tr.select("a").first();

String dataTitle = tr.attr("data-title");
String href = link.attr("href");

Upvotes: 1

Related Questions