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, while executing I find these errors. How to resolve? I have downloaded Jsoup.jar file in my folder location. 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")) {
The ones of Jsoup of course.
Also see the Jsoup API documentation.
That said, there’s another problem which would only manifest when you got it run: you’re passing the URL in flavor of a
java.lang.Stringinstead of ajava.net.URL. AStringwould be treated as plain HTML, not as a resource. Fix it as well:Update: you just need to ensure that Jsoup libraries are present in both the compiletime and runtime classpath. When using
javac.exeandjava.exe, use the-cpargument. E.g. to compile it:and to execute it: