我希望有人可以帮助我,因为我一直在寻找它,但没有找到任何工作。

我正在从列表中连接到多个URL,一切正常工作,但是我开始获得404个错误,现在我想捕获这个错误,以便程序不会终止并继续通过列表URL。

这是我收到的错误

org.jsoup.HttpStatusException: HTTP error fetching URL. Status=404, URL=http:nameofthesite
.

我正在使用jsoup.connect and错误是在这行代码中引起的

    Document doc= Jsoup.connect(countryUrl[i2]).timeout(10*1000)                      
    .userAgent("Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5")
    .get();
.

如何更改代码,以便我可以获得状态代码。 我已经尝试了connection.Response(我在这个网站上发现的东西是解决此类问题的解决方案),但我正在收到铸造错误

 Connection.response  response= Jsoup.connect(countryUrl[i2]).timeout(10*1000)                      
            .userAgent("Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5")
            .execute();
            int statusCode = response.statusCode();
            if(statusCode==200){
.

但我收到以下错误

groovy.lang.MissingMethodException: No signature of method: static org.jsoup.Connection.response() is applicable for argument types: (org.jsoup.helper.HttpConnection$Response) values: [org.jsoup.helper.HttpConnection$Response@c7325ae]
Possible solutions: respondsTo(java.lang.String), respondsTo(java.lang.String, [Ljava.lang.Object;)
.

任何帮助将欣赏,谢谢。

有帮助吗?

解决方案

您的代码中有一个拼写错误:

Connection.response response = Jsoup.connect(...) ...
//         ^
//         |
.

Response是一个静态类(界面是正确的)的世代odicetagcode,所以只需更改代码:

Connection.Response response = Jsoup.connect(...) ...
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top