如何在android中使用Jsoup解析HTML标记
我正在开发一个android应用程序,其中我正在使用android中的Jsoup解析来自网站的html内容如何在android中使用Jsoup解析HTML标记,android,html,parsing,android-activity,jsoup,Android,Html,Parsing,Android Activity,Jsoup,我正在开发一个android应用程序,其中我正在使用android中的Jsoup解析来自网站的html内容 为此,我写了: @Override protected Void doInBackground(Void... params) { try { // Connect to the web site org.jsoup.nodes.Document document = Jsoup.c
为此,我写了:
@Override
protected Void doInBackground(Void... params) {
try {
// Connect to the web site
org.jsoup.nodes.Document document = Jsoup.connect(url).get();
// Get the html document title
title=document.select("meta[name=title]");
desc = title.attr("content");
} catch (IOException e) {
e.printStackTrace();
} catch(NullPointerException ex){
System.out.println(ex);
}
return null;
}
@Override
protected void onPostExecute(Void result)
{
// Set title into TextView
t1.setText(desc);
}
这工作正常,没有任何问题,并显示在活动的文本视图中。现在我想解析那个网站上的h3标签
<h3 xmlns="http://www.w3.org/1999/xhtml" id="sites-page-title-header" style="" align="left">
<span id="sites-page-title" dir="ltr">Notices for the week</span>
</h3>
本周通告
我不知道如何在android活动中使用TextView来实现这一点和显示这一点。请建议我…如果我想解析整个div标记并使用textView将其显示到活动中,也请建议我 您可以直接选择h3标签,如下所示:
String h3=document. select("h3").text();
textView.setText(h3);
或
试试这个,解析的问题在哪里?从文档中选择
h3
-标记可以正常工作。
textView. setText(document.select("span[id=sites-page-title]").first().text());