Reputation: 6150
I want to parse one paragraph from a website. I want to parse the first paragraph in post div:
I am using AsyncTask to retrieve the data. This is the doInBackground function:
@Override
protected Elements doInBackground(String... url) {
Document doc = null;
try {
doc = Jsoup.connect(url[0]).timeout(10*1000).get();
return doc.select("div.post > p");
} catch (Exception e) {
e.printStackTrace();
}
return new Elements();
}
However I always get this in Logcat:
java.io.IOException: -1 error loading URL http://www.vaccinestoday.eu/diseases/disease/rabies/
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:414) at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:391) at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:157) 05-17 at org.jsoup.helper.HttpConnection.get(HttpConnection.java:146) 05-17 at com.c0dehunter.aZDR.diseaseActivity$getDataTask.doInBackground(diseaseActivity.java:46) at com.c0dehunter.aZDR.diseaseActivity$getDataTask.doInBackground(diseaseActivity.java:1) at android.os.AsyncTask$2.call(AsyncTask.java:185) 05-17 10:22:32.937: at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) at java.util.concurrent.FutureTask.run(FutureTask.java:137) 05-17 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) at java.lang.Thread.run(Thread.java:1096)
If you click on link you'll see you can open it normally. What is the problem here?
Upvotes: 3
Views: 667
Reputation: 1205
I ran your connect and it ran just fine. I can't say the same about your query. It doesn't bring you exactly what you want.. So i kind of enhanced it:
doc.select("div[class=post-entry] > p");
doc.select("div.post-entry > p");
Any of those will basically get ALL of the post. From now on, you can keep going solo, can't you? Anything else you need, just ask.
Upvotes: 2