Note that there are some explanatory texts on larger screens.

plurals
  1. POJsoup, extract links, images, from website. Exception on runtime
    primarykey
    data
    text
    <p>I am just starting to play around with Jsoup, so followed the tutorial they had on there website. This code i assume should work fine but when i am running it on netbeans I am coming across errors.</p> <p>This is the code i am using:</p> <p>`</p> <pre><code>/** * * @author Slabs One */ public class ParseWebpage { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { Validate.isTrue(args.length == 1, "http://www.gumtree.com.au/"); String url = args[0]; print("Fetching %s...", url); Document doc = Jsoup.connect(url).get(); Elements links = doc.select("a[href]"); Elements media = doc.select("[src]"); Elements imports = doc.select("link[href]"); print("\nMedia: (%d)", media.size()); for (Element src : media) { if (src.tagName().equals("img")) print(" * %s: &lt;%s&gt; %sx%s (%s)", src.tagName(), src.attr("abs:src"), src.attr("width"), src.attr("height"), trim(src.attr("alt"), 20)); else print(" * %s: &lt;%s&gt;", src.tagName(), src.attr("abs:src")); } print("\nImports: (%d)", imports.size()); for (Element link : imports) { print(" * %s &lt;%s&gt; (%s)", link.tagName(),link.attr("abs:href"), link.attr("rel")); } print("\nLinks: (%d)", links.size()); for (Element link : links) { print(" * a: &lt;%s&gt; (%s)", link.attr("abs:href"), trim(link.text(), 35)); } } private static void print(String msg, Object... args) { System.out.println(String.format(msg, args)); } private static String trim(String s, int width) { if (s.length() &gt; width) return s.substring(0, width-1) + "."; else return s; } } </code></pre> <p>`</p> <p>There shouldnt be any problems with this code, but on runtime i get this error:</p> <pre><code> Exception in thread "main" java.lang.IllegalArgumentException: http://www.gumtree.com.au/ at org.jsoup.helper.Validate.isTrue(Validate.java:45) at parsewebpage.ParseWebpage.main(ParseWebpage.java:25) </code></pre> <p>Any insight to why this is not working would be greatly appreciated</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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