Skip to content

Instantly share code, notes, and snippets.

@shelling
Created October 4, 2011 14:22
Show Gist options
  • Select an option

  • Save shelling/1261756 to your computer and use it in GitHub Desktop.

Select an option

Save shelling/1261756 to your computer and use it in GitHub Desktop.
import org.jsoup.Jsoup;
import org.jsoup.nodes.*;
import org.jsoup.select.*;
public class HelloParser {
public static void main(String[] args) {
try {
Document doc = Jsoup.parse("<html><body><p class=content>內容</p></body></html>");
Element p = doc.select("p.content").first();
System.out.println(p.html());
} catch (Exception e) {
e.printStackTrace();
}
try {
Document doc = Jsoup.connect("https://market.android.com/search?q=twitter").get();
Elements apps = doc.select("a.title");
for (Element app : apps) {
System.out.println(app.attr("title"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment