嗨朋友我开发了一个应用程序来解析android中的网页。如何在Android中解析<div class ="abc"><h4 class="cvb">india</h4></div>
<div class="list-group"><h4 class="list-group-item ui-header"NZ vs RSA, Christchurch</h4></div>.
我想解析NZ vs RSA Christchurch
,请帮帮我。
嗨朋友我开发了一个应用程序来解析android中的网页。如何在Android中解析<div class ="abc"><h4 class="cvb">india</h4></div>
<div class="list-group"><h4 class="list-group-item ui-header"NZ vs RSA, Christchurch</h4></div>.
我想解析NZ vs RSA Christchurch
,请帮帮我。
试试Jsoup
libray here。它是您可以选择的最佳方式。
public static String html2text(String html) {
return Jsoup.parse(html).text();
}
或者你可以使用默认的android Html.fromHtml()
。
String normalString = android.text.Html.fromHtml(stringforparse).toString()
转到我上面提供的链接,下载库,将库添加到项目中,使用放置在此处的第一个代码,将字符串传递给函数,然后将它将返回您需要的值。 – 2015-02-11 07:30:17
公共类MainActivity扩展活动{TextView text; \t String ss; \t @Override \t保护无效的onCreate(捆绑savedInstanceState){ \t \t // TODO自动生成方法存根 \t \t super.onCreate(savedInstanceState); \t \t setContentView(R.layout.activity_main); \t \t text =(TextView)findViewById(R.id.text); \t ss = html2text(“http://m.cricbuzz.com/cricket-match/live-scores”); \t \t text.setText(“”+ ss); \t \t \t} \t公共静态字符串html2text(字符串HTML){ \t回Jsoup.parse(HTML)的.text(); \t}} 和答案是http://m.cricbuzz.com/cricket-match/live-scores – user2447552 2015-02-11 07:54:34
您可以使用
String extractedString = android.text.Html.fromHtml(htmlString).toString();
fromHtml(String source)
方法返回从提供的HTML字符串显示的样式文本。
请尝试JSOUP解析HTML标签.. – 2015-02-11 06:59:44
请分享我一个样本。 – user2447552 2015-02-11 07:03:19
请谷歌它的基础上的JSOUP ..你会发现更多的例子.. – 2015-02-11 07:04:45