我正在为我的看板社区制作一个 Android 应用程序。董事会提供者为我提供一般类别的 RSS 提要,但不生成主题提要。因此,我从这些提要中检索主题 URL,并希望使用 Jsoup 解析 HTML 并将其提供给 WebView。
除了不返回任何内容的 select() 函数外,它工作得很好。
“HTML RETREIVED”日志给我:<html><head><title>The topic title</title></head><body></body></html>
h1 标签在代码中用于测试目的:它在 WebView 和解析网页的标题上显示良好。
我还将日志行放在 select() 行之后。它也不返回任何内容。
我已经尝试在一个纯 Java 项目中仅使用 Jsoup 进行解析,并且一切顺利。 所以我假设 Android 有问题。
PS:互联网许可在 list 中处于 Activity 状态。
我错过了什么吗?
代码如下:
String html;
Bundle param = this.getIntent().getExtras();
String url = param.getString("url");
try {
Document doc = Jsoup.connect(url).get();
doc.select(".topic .clear").remove();
String title = doc.title().toString();
html = doc.select(".username strong, .entry-content").toString();
html = "<html><head><title>"+title+"</title></head><body><h1>"+title+"</h1>"+html+"</body></html>";
WebView webview = new WebView(this);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setProgress(progress * 1000);
Log.d("LOADING",""+ progress);
}
});
webview.loadData(html, "text/html", "UTF-8");
//webview.loadUrl(url);
Log.i("HTML RETREIVED", ""+html);
} catch (IOException e) {
Log.e("ERROR", "Error while generate topic");
}
最佳答案
好的,我发现了一些有趣的东西。
我要选择的类(class)不在这里,因为我正在获取网页的移动版本。 Android 应用程序似乎使用了移动用户代理,这很正常但没有在任何地方说。
不管怎样,我知道现在在想什么。
关于android - Jsoup select() 在 Android 应用程序中不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8439739/