【问题标题】:Parse data with Jsoup使用 Jsoup 解析数据
【发布时间】:2020-02-03 15:24:41
【问题描述】:

我有一个包含这些数据的字符串:

<div>
  <a href='https://www.some.html'>
    <img src='https://besttv232.jpg' alt='null' title='null' border='0' width='100' height='56'>
  </a>
</div>
Some text is also over here

我需要用 Jsoup 解析它,我需要 a href url、img url 和数据(一些文本...)

我试过了:

Document doc = Jsoup.parse(myData); //myData is string with content above
Elements links = content.get("div");

for (Element link : links) {
    String linkHref = link.attr("href");
    String linkHrefa = link.attr("img");
    String linkText = link.text();
}

【问题讨论】:

    标签: android jsoup


    【解决方案1】:

    我需要一个 href 网址

    Element a = doc.select("a").first();
    String src = a.attr("href");
    
    

    图片网址

    Element img = doc.select("img").first();
    String src = img.attr("src");
    

    数据

    String content = doc.body().text();
    

    【讨论】:

      猜你喜欢
      • 2014-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 2014-09-09
      • 2019-12-04
      • 2019-06-04
      • 1970-01-01
      相关资源
      最近更新 更多