Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use a HTML parser like <a href="http://jsoup.org" rel="noreferrer">Jsoup</a>. This has my preference above the <a href="https://stackoverflow.com/questions/3152138/what-are-the-pros-and-cons-of-the-leading-java-html-parsers">other HTML parsers available in Java</a> since it <a href="http://jsoup.org/cookbook/extracting-data/selector-syntax" rel="noreferrer">supports</a> <a href="http://jquery.com" rel="noreferrer">jQuery</a> like <a href="http://www.w3.org/TR/CSS2/selector.html" rel="noreferrer">CSS selectors</a>. Also, its class representing a list of nodes, <a href="http://jsoup.org/apidocs/org/jsoup/select/Elements.html" rel="noreferrer"><code>Elements</code></a>, implements <a href="http://java.sun.com/javase/6/docs/api/java/lang/Iterable.html" rel="noreferrer"><code>Iterable</code></a> so that you can iterate over it in an <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/foreach.html" rel="noreferrer">enhanced for loop</a> (so there's no need to hassle with verbose <code>Node</code> and <code>NodeList</code> like classes in the average Java DOM parser).</p> <p>Here's a basic kickoff example (just put the <a href="http://jsoup.org/download" rel="noreferrer">latest Jsoup JAR file</a> in classpath):</p> <pre><code>package com.stackoverflow.q2835505; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; public class Test { public static void main(String[] args) throws Exception { String url = "https://stackoverflow.com/questions/2835505"; Document document = Jsoup.connect(url).get(); String question = document.select("#question .post-text").text(); System.out.println("Question: " + question); Elements answerers = document.select("#answers .user-details a"); for (Element answerer : answerers) { System.out.println("Answerer: " + answerer.text()); } } } </code></pre> <p>As you might have guessed, this prints your own question and the names of all answerers.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload