使用 Jsoup 解析数据



我有包含此数据的字符串:

<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解析它,我需要href网址,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();
}

我需要 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();

最新更新