Ciao a tutti,
premetto che sono quasi 10 anni che non tocco Java e provengo da PHP ... quindi perdonatemi se potrei commettere dei errori imbarazzanti.
Volevo testare una piccola app per fare il parsing di una pagina HTML quindi ho trovato un tutorial con questo codice ma qualcosa non funziona in fase di compilazione.
Il package è contenuto nella stessa cartella del file leggiHTML.javacodice:import java.net.*; import java.io.*; import jtidy.jar; public class leggiHTML { publicstaticvoid main() { URL url = new URL("http://www.miosito.com"); 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);
In compilazione ottengo:
Da quanto vedo non trova la libreria .jar, dove sbaglio?codice:leggiHTML.java:3: error: package jtidy does not exist import jtidy.jar; ^ leggiHTML.java:10: error: cannot find symbol Tidy tidy = new Tidy(); ^ symbol: class Tidy location: class leggiHTML leggiHTML.java:10: error: cannot find symbol Tidy tidy = new Tidy(); ^ symbol: class Tidy location: class leggiHTML leggiHTML.java:13: error: cannot find symbol Document response = tidy.parseDOM(page, null); ^ symbol: class Document location: class leggiHTML leggiHTML.java:15: error: cannot find symbol XPathFactory factory = XPathFactory.newInstance(); ^ symbol: class XPathFactory location: class leggiHTML leggiHTML.java:15: error: cannot find symbol XPathFactory factory = XPathFactory.newInstance(); ^ symbol: variable XPathFactory location: class leggiHTML leggiHTML.java:16: error: cannot find symbol XPath xPath=factory.newXPath(); ^ symbol: class XPath location: class leggiHTML leggiHTML.java:18: error: cannot find symbol NodeList nodes = (NodeList)xPath.evaluate(pattern, response, XPathConstants.NODESET); ^ symbol: class NodeList location: class leggiHTML leggiHTML.java:18: error: cannot find symbol NodeList nodes = (NodeList)xPath.evaluate(pattern, response, XPathConstants.NODESET); ^ symbol: class NodeList location: class leggiHTML leggiHTML.java:18: error: cannot find symbol NodeList nodes = (NodeList)xPath.evaluate(pattern, response, XPathConstants.NODESET); ^ symbol: variable XPathConstants location: class leggiHTML 10 errors

Rispondi quotando