What packages do you need to import?

import java.io.*; import java.net.URL; import java.net.URLConnection; import java.sql.*; public class linksfind{ public static void main(){ String html = "http://www.apple.com/pr/"; Document document = Jsoup.parse(html); // Can also take an URL. for (Element element : document.getElementsByTag("a")) { System.out.println(element.attr("href")); } } } 

Guys, In the above program at runtime I find these errors. How to allow? I uploaded the Jsoup.jar file to a folder. What else should I do?

 linksfind.java:8: cannot find symbol symbol : class Document location: class linksfind Document document = Jsoup.parse(html); // Can also take a ^ linksfind.java:8: cannot find symbol symbol : variable Jsoup location: class linksfind Document document = Jsoup.parse(html); // Can also take a ^ linksfind.java:9: cannot find symbol symbol : class Element location: class linksfind for (Element element : document.getElementsByTag("a")) { 
+4
source share
3 answers

Of course, Jsoup.

 import org.jsoup.nodes.Document; import org.jsoup.Jsoup; import org.jsoup.nodes.Element; 

Also see the Jsoup API documentation.


However, there is another problem that will only appear when you run it: you pass the url in the flavor of java.lang.String instead of java.net.URL . A String will be considered as plain HTML, not as a resource. Fix it:

 URL url = new URL("http://www.apple.com/pr/"); Document document = Jsoup.parse(url, 3000); 

Update : you just need to make sure the Jsoup libraries are present both in the compilation class and in the runtime. When using javac.exe and java.exe use the -cp argument. For instance. compile it:

 javac -cp .;/path/to/jsoup.jar com/example/YourClass.java 

and execute it:

 java -cp .;/path/to/jsoup.jar com.example.YourClass 
+10
source

It looks like you are missing the jsoup library from your class path. Then you should import the necessary org.jsoup packages. *,

0
source

It seems that jsoup.jar is not inserted correctly and is missing at compile time. Jsoup has only one dependency (commons lang) , so other missing external dependencies do not seem to be an immediate problem in your case.

You can try Maven or Ivy to resolve your dependencies if you don't want to do it manually.

0
source

All Articles