2
我想知道如何在HTML中獲取標籤內的信息。我不知道我是否做得對,因爲它沒有返回任何信息。我向你展示我的android代碼,看看你能否幫助我。如何從HTML WebView中的標籤獲取信息?
代碼類:
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>
我希望我正確解釋! 謝謝你! ;)