我想知道如何在 HTML 的标签中获取信息。我不知道我是否做得对,因为它不返回任何信息。我向您展示我的android代码,看看您是否可以帮助我。
代码类:
public class WebView1 extends Activity {
/** Called when the activity is first created. */
WebView browse;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview1);
browse = (WebView) findViewById(R.id.webview1);
browse.setWebChromeClient(new WebChromeClient());
browse.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
File input = new File("file:///android_asset/ejemploWebview.html");
Document doc = null;
try {
doc = Jsoup.parse(input, "UTF-8");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//http://jsoup.org/cookbook/input/load-document-from-url
//Document doc = Jsoup.connect("http://example.com/").get();
Element content = doc.getElementById("div");
Elements links = content.getElementsByTag("id");
String linkId = links.attr("manolo");
System.out.print(linkId); //I need that it return Hiiii!
}
}); } }
代码HTML:
<html>
<head>
</head>
<div id="james">hellooo!</div>
<div id="paco">byeee!</div>
<div id="manolo">Hiii!</div>
</html>
我希望我解释正确!谢谢!;)