codice:
static URL url;
public static void main(String[] args) throws IOException, XPathExpressionException {
// TODO Auto-generated method stub
URL url = new URL("http://www.paginaprova.it");
BufferedInputStream page = new BufferedInputStream(url.openStream());
Tidy tidy = new Tidy();
tidy.setQuiet(true);
tidy.setShowWarnings(false);
Document response = tidy.parseDOM(page, null);
XPathFactory factory = XPathFactory.newInstance();
XPath xPath=factory.newXPath();
String pattern = "//body/a";
NodeList nodes = (NodeList)xPath.evaluate(pattern, response, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
System.out.println((String) nodes.item(i).getNodeValue());
}
}
praticamente dovrebbe stampare i nodi però non stampa niente...