1

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

<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 日 - 由于墨菲高中搬迁至 Clark-Shaw 校区以及仍在进行中的必要建设,Clark-Shaw 学校没有参加 1 月 11 日至 12 日的磁铁学校“See and Sign”。我们想恢复学校参观和会见感兴趣的家长。因此,我们计划在 1 月 25 日星期五上午 9:00 至下午 12:00 举行“开放日”,以配合当天安排的学校科学博览会开放日。

请与您的朋友和邻居分享此信息。Magnet School 应用程序现已在线提供。*

我怎样才能在android中实现它。

4

2 回答 2

3

使用 jsoup http://jsoup.org/你可以得到这个

下载 jsoup.jar 文件然后将其添加到您的 libs 文件夹然后转到 android 依赖项右键单击 >> 构建路径 >> 配置构建路径 >> 添加 JARS >> 库 >> 然后选择您下载的 jsoup.jar 文件

 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);
    }
于 2013-01-22T05:32:40.943 回答
1

由于这是 Html 文档,请尝试将 Html.fromHtml(string) 用于 TextView 或尝试使用 webview 取决于标签。

对于 TextView 你可以这样使用

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();

于 2013-01-22T06:05:01.117 回答