"<p><img src="https://fashion-world.cn/mall/image/catalog/rea/176417753356354772.jpg"><img src="https://fashion-world.cn/mall/image/catalog/rea/360-300.png"></p><h1>我们是VR</h1>"
上面这段html字符串该如何解析啊,谁能写个示例吗????
使用静态Jsoup.parse(String html) 方法或 Jsoup.parse(String html, String baseUri)示例代码:
String html = "
First parse"Parsed HTML into a doc.
"; Document doc = Jsoup.parse(html);parse(String html, String baseUri) 这方法能够将输入的HTML解析为一个新的文档 (Document),参数 baseUri 是用来将相对 URL 转成绝对URL,并指定从哪个网站获取文档。如这个方法不适用,你可以使用 parse(String html) 方法来解析成HTML字符串如上面的示例。.
只要解析的不是空字符串,就能返回一个结构合理的文档,其中包含(至少) 一个head和一个body元素。
一旦拥有了一个Document,你就可以使用Document中适当的方法或它父类 Element和Node中的方法来取得相关数据。
http://www.open-open.com/jsoup/parse-document-from-string.htm
可以使用jsoup框架 ,网上提供了很多例子了
你这个不是完成html代码,可以使用jsoup框架
最后我自己说下方法,对于这些不完整的并且不是标准的html字符串,首先用Jsoup,Document doc = Jsoup.parse(html);doc.getbody(),再get其中text,之后可以用TextView.setText(Html.fromHtml....)的方法来直接解析text中的标准html字符串显示出文字图片