我想用richtext来显示html内容,所以我解析了url尝试获取<div class="margin-box"></div>
中的所有内容为String值。 但我无法解析网址。 代码象下面这样:Android使用JSoup解析HTML转换为字符串
用户汤解析URL
Document document = Jsoup.parse(news_url);
String news_content = CommonUtil.newsContent(document);
数据捕获
public static String newsContent(Document document){
Elements elements = document.select("div.margin-box");
String newsContent = elements.toString();
return newsContent;
}
显示URL解析不成功。 其实我想要得到像下面的值:
<div>
<p>
<imgsrc="http://p1.pstatp.com/large/1c67000332373537f0ff" img_width="640" img_height="360" inline="0" alt=“************” onerror="javascript:errorimg.call(this);">
</p>
<p class="pgc-img-caption”>***********</p><p>*************************************</p>
<p><imgsrc="http://p3.pstatp.com/large/1c6e0000841ab42ca326" img_width="640" img_height="425" inline="0" alt=“**********”onerror="javascript:errorimg.call(this);"></p>
<p class="pgc-img-caption”>********************************</p>
<p><img src="http://p1.pstatp.com/large/1c6d00008eebccce3e2f" img_width="550" img_height="375" inline="0" alt=“************” onerror="javascript:errorimg.call(this);"></p>
<p class="pgc-img-caption”>*********</p><p>**************************</p><p>*********************</p><p>*****************</p></div>
我做了什么错?
您可以发布网址或完整的html块吗? –
好吧,我会编辑和添加完整的html块 –
@ProkashSarkari已添加完整的html块 –