首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Android中解析网站中的Html标签

如何在Android中解析网站中的Html标签
EN

Stack Overflow用户
提问于 2013-01-22 13:14:53
回答 2查看 4.2K关注 0票数 1

我正在尝试从以下网址获取标记中的文本:http://www.mcpss.com/?PN='News2'&SubP='DNewsStory'&gn=&NewsID=47318&ShowNav=&StoryGroup=Current

代码语言:javascript
复制
<td class="header">

OPEN HOUSE SCHEDULED AT CLARK-SHAW

</td>

<p><span style="font-size: 12pt;">January 16, 2013 - Due to the relocation of Murphy High School to the Clark-Shaw campus and the necessary construction that is still ongoing, Clark-Shaw school did not participate in the magnet school &ldquo;See and Sign&rdquo; January 11 and 12<sup>th</sup>. We would like to resume giving school tours and meeting interested parents. Therefore, we are planning an &ldquo;Open House&rdquo; on Friday, January 25 from 9:00 a.m.- 12:00 p.m. to coincide with our school&rsquo;s Science Fair Open House that is scheduled for that day.</span></p>
<p><span style="font-size: 12pt;">&nbsp;</span></p>
<p><span style="font-size: 12pt;">Please share this information with your friends and neighbors.&nbsp;&nbsp; Magnet School applications are available now online.</span></p>
<p>&nbsp;</p>

我想在android应用程序中表示文本,如下所示:

*计划在CLARK-SHAW举行的开放日

2013年1月16日-由于墨菲高中搬迁到克拉克-肖校区,必要的建设仍在进行中,克拉克-肖学校没有参加磁铁学校的“见并签署”1月11日和12日。我们希望恢复提供学校参观和会见感兴趣的家长。因此,我们计划在1月25日(星期五)上午9:00 -下午12:00举行“开放参观”。恰逢我校定于当天举行的科学博览会开放日。

请与您的朋友和邻居分享此信息。磁石学校申请现已在线提供。*

我怎样才能在android中获得它。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-22 13:32:41

使用jsoup http://jsoup.org/,您可以获得以下内容

下载jsoup.jar文件,然后将其添加到您的libs文件夹中,然后转到安卓依赖项,右键单击>> build path >> configure build path >> add JARS>> libs >>,然后选择您下载的jsoup.jar文件

代码语言:javascript
复制
 try {
      String website="http://www.mcpss.com/?PN='News2'&SubP='DNewsStory'&gn=&NewsID=47318&ShowNav=&StoryGroup=Current";
      Document doc = Jsoup.connect(website).get();
      Elements el=doc.getElementsByClass("header");
      String text=el.text();
    } catch (Exception e) {
        Log.wtf("name of activity","error message to show in log", e);
    }
票数 3
EN

Stack Overflow用户

发布于 2013-01-22 14:05:01

由于这是一个超文本标记语言文档,请尝试对TextView使用Html.fromHtml(字符串),或者尝试使用webview取决于标签。

对于TextView,您可以像这样使用

代码语言:javascript
复制
TextView txt=new TextView(getApplicationContext());
        String str="<td class=\"header\">"+
        "OPEN HOUSE SCHEDULED AT CLARK-SHAW"+
        "</td>"+
        "<p><span style=\"font-size: 12pt;\">January 16, 2013 - Due to the relocation of Murphy High School to the Clark-Shaw campus and the necessary construction that is still ongoing, Clark-Shaw school did not participate in the magnet school &ldquo;See and Sign&rdquo; January 11 and 12<sup>th</sup>. We would like to resume giving school tours and meeting interested parents. Therefore, we are planning an &ldquo;Open House&rdquo; on Friday, January 25 from 9:00 a.m.- 12:00 p.m. to coincide with our school&rsquo;s Science Fair Open House that is scheduled for that day.</span></p>"+
        "<p><span style=\"font-size: 12pt;\">&nbsp;</span></p>"+
        "<p><span style=\"font-size: 12pt;\">Please share this information with your friends and neighbors.&nbsp;&nbsp; Magnet School applications are available now online.</span></p>"+
        "<p>&nbsp;</p>";

        txt.setText(Html.fromHtml(str));

对于WebView,尝试使用webview.loadData();

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14451986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档