好的,我正在尝试获取 data-title 和 href 并将它们分配给 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&index=1&list=PL6gx4Cwl9DGDV6SnbINlVUd0o2xT4JbMu"
最佳答案
如果您不介意包含依赖项,那么有一个很好的库可以用于此类内容,名为 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");
关于java - 从 html 文件中获取信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35207171/