0
我會jsoup解析此頁:http://www.verlata.it/eventi 並在此我doInBackground()方法:解析jsoup錯誤。根元素空
@Override
protected String doInBackground(Void... params) {
try {
errore = false;
final Document doc = Jsoup.connect("http://www.verlata.it/eventi").timeout(30000).get();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (doc != null) {
rootElement = doc.body().getElementById("div#container");
} else {
errore = true;
Log.d("errore", "errore parsing 1");
notFound.setVisibility(View.VISIBLE);
notFound.setText("Ops, something went wrong. Maybe the blog is offline or please check your connection.");
}
if (rootElement != null) {
Elements elements = rootElement.getElementsByTag("div#body_content");
for(Element element : elements){
if (!errore) {
String descrizione = element.select("div").text();
String titolo = element.select("h2").text();
//String urldesc = element.select("h2 a").first().attr("abs:href");
titoli.add(titolo);
descrizioni.add(descrizione);
//url.add(urldesc);
} else {
errore = true;
break;
}
}
} else {
errore = true;
Log.d("errore", "errore parsing 2");
notFound.setVisibility(View.VISIBLE);
notFound.setText("Ops, something went wrong. Maybe the blog is offline or please check your connection.");
}
}
});
} catch (Exception e) {
e.printStackTrace();
/*Toast.makeText(FragmentThree.this, "Errore parsing",
Toast.LENGTH_SHORT).show();*/
Log.d("errore", "errore parsing");
notFound.setVisibility(View.VISIBLE);
notFound.setText("Ops, something went wrong. Maybe the blog is offline or please check your connection.");
}
return null;
}
的logcat的報告我:Log.d("errore", "errore parsing 2");
所以這意味着rootElement的是空..怎麼可能?我需要的是帖子的標題及其描述。
MMH我試過,但我得到了同樣的錯誤......我不知道爲什麼..也許錯的ID? –
@ End.Game你用'doc.select'試過了嗎? – BackSlash
以及我認爲這個網站有問題..「描述」是一個div ..沒有任何id ..我可以解析它嗎? –