3

I want to parse one paragraph from a website. I want to parse the first paragraph in post div:

enter image description here

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?

1
  • Did you try this on a real device as well ? I keep getting the same error on emulator but on device, it smoothly works. Commented May 17, 2012 at 11:14

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.