我正在尝试从下面的标签中获取文本
网址: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 “See and Sign” January 11 and 12<sup>th</sup>. We would like to resume giving school tours and meeting interested parents. Therefore, we are planning an “Open House” on Friday, January 25 from 9:00 a.m.- 12:00 p.m. to coincide with our school’s Science Fair Open House that is scheduled for that day.</span></p>
<p><span style="font-size: 12pt;"> </span></p>
<p><span style="font-size: 12pt;">Please share this information with your friends and neighbors. Magnet School applications are available now online.</span></p>
<p> </p>
我想在Android应用程序中表示文本,如下所示:
*在CLARK-SHAW安排的开放式房屋
2013年1月16日 - 由于Murphy高中搬迁至Clark-Shaw校区并且仍在进行必要的施工,Clark-Shaw学校于1月11日没有参加磁铁学校“See and Sign” 12。我们希望恢复参加学校旅行和会见有兴趣的家长。因此,我们计划于1月25日星期五上午9点至中午12点开放“开放日”。与我们学校当天安排的科学博览会开放日同时进行。
请与您的朋友和邻居分享这些信息。磁铁学校的申请现已在线提供。*
我怎么能在android中实现它。
答案 0 :(得分:1)
使用jsoup http://jsoup.org/你可以得到这个
下载jsoup.jar文件,然后将其添加到您的libs文件夹,然后转到android dependancies右键单击&gt;&gt;构建路径&gt;&gt;配置构建路径&gt;&gt;添加JARS&gt;&gt; libs&gt;&gt;然后选择你下载的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);
}
答案 1 :(得分: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 “See and Sign” January 11 and 12<sup>th</sup>. We would like to resume giving school tours and meeting interested parents. Therefore, we are planning an “Open House” on Friday, January 25 from 9:00 a.m.- 12:00 p.m. to coincide with our school’s Science Fair Open House that is scheduled for that day.</span></p>"+
"<p><span style=\"font-size: 12pt;\"> </span></p>"+
"<p><span style=\"font-size: 12pt;\">Please share this information with your friends and neighbors. Magnet School applications are available now online.</span></p>"+
"<p> </p>";
txt.setText(Html.fromHtml(str));
对于WebView,尝试使用webview.loadData();