I am writing a crawler with Jsoup and this is the HTTP error I get:
org.jsoup.HttpStatusException: HTTP error fetching URL. Status=404, URL=https://www.mkyong.com/spring-boot/spring-boot-hibernate-search-example/%E2%80%9Chttp:/wildfly.org/downloads/
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:760)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:757)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:706)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:299)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:288)
at testing.DefinitelyNotSpiderLeg.crawl(DefinitelyNotSpiderLeg.java:31)
at testing.DefinitelyNotSpider.search(DefinitelyNotSpider.java:33)
at testing.Test.main(Test.java:9)
I read all the other similar questions and solutions about this error, so I implemented their solutions into my code, but I still get the same error when the Jsoup connects to the url.
This is the method I use for crawling:
public boolean crawl(String url)
{
try
{
Document htmlDocument = Jsoup.connect(url)
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1")
.referrer("http://www.google.com")
.timeout(1000*5) //it's in milliseconds, so this means 5 seconds.
.get();
Elements linksOnPage = htmlDocument.select("a[href]");
for(Element link : linksOnPage)
{
String a =link.attr("abs:href");
if(a.startsWith(url)) {
this.links.add(a);
}
}
}catch (NullPointerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (HttpStatusException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
Any ideas guys???