9

I was just wondering has anyone got a sample eclipse project with a working implementation of JSoup? Im trying to use it to pull information from websites and have gone all over google trying to get it to work but cant. If anyone could help I'd really appreciate it.

dbaby7
  • 159
  • 1
  • 4
  • 11
  • I cant get any sort of working apps...I've tried putting together code from the web but it wont wont...Im new to the Android development so finding it quite hard – dbaby7 Mar 03 '11 at 14:15
  • It's better to ask for help with problems than asking for help to find samples. You might still run into trouble with samples. Just ask a clear question along with a code snippet and the exact error/exception you got. – BalusC Mar 16 '11 at 00:26

1 Answers1

25

JSoup is really easy to use, look at these exemples from the JSoup cookbook:here

First, You have to connect to the webpage you want to parse using:

Document doc = Jsoup.connect("http://example.com/").get();

Then, you can select page elements using the JSoup selector syntax.

For instance, say you want to select all the content of the div tags with the id attribute set to test, you just have to use:

Elements divs = doc.select("div#test");

to retrieve the divs, then you can iterate on them using:

for (Element div : divs)
    System.out.println(div.text());
}
Swathin
  • 516
  • 1
  • 8
  • 23
Nicolas Girardin
  • 607
  • 5
  • 14