【问题标题】:How to get information using jsoup如何使用jsoup获取信息
【发布时间】:2015-01-10 13:25:29
【问题描述】:

我有这个 html

<td rowspan="3" class="event start"> <a href="/search/1065650;1/note">INFO1<br>DETAIL1 DETAIL2<br>INFO2</a> </td> 

如何使用 jsoup 获取 INFO1 和 INFO2??

【问题讨论】:

    标签: java html parsing tags jsoup


    【解决方案1】:

    尝试类似的方法:

    Document doc = Jsoup.connect(url).get();
    Elements td=doc.select("td.event.start");
    Elements a = td.first().getElementsByTag("a");
    String [] words = a.text().split(" ");
    System.out.println(words[0]+" "+words[3]);
    

    测试日期:

    <!doctype html>
    <html>
    <body>
    <td rowspan="3" class="event start"> 
     <a href="/search/1065650;1/note">
      INFO1<br>DETAIL1 DETAIL2<br>INFO2
      </a> 
    </td> 
    </body>
    </html>

    【讨论】:

    • 它有效。刚测试过。您使用的是哪个版本的 Jsoup?原理是用css类“event”和“start”找到td,然后得到一个文本内容,它将是“INFO1 DETAIL1 DETAIL2 INFO2”,然后得到这些单词的第一个和最后一个。我将在我的答案中添加我的测试文件以进行检查
    猜你喜欢
    • 1970-01-01
    • 2022-01-03
    • 2014-03-17
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多