0
雖然我通過jsoup連接到一個URL。這裏是我的代碼片段:儘管狀態碼檢查,jsoup會拋出204狀態
for (int j = 0; j < unq_urls.size(); j++) {
Response response2 = Jsoup.connect(unq_urls.get(j))
.userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21")
.timeout(100*1000)
.ignoreContentType(true)
.execute();
if (response2.statusCode() == 200) {
...}
}
當執行jsoup連接引發以下錯誤:
org.jsoup.HttpStatusException: HTTP error fetching URL. Status=204, URL=https://www.google.com/gen_204?reason=EmptyURL
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:459)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:475)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:475)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:434)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:181)
at cseapiandparsing.CSE_Author_Name_Dis.<init>(CSE_Author_Name_Dis.java:187)
at cseapiandparsing.CSE_Author_Name_Dis.main(CSE_Author_Name_Dis.java:263)
我如何克服這個問題?我的意思是我想讓jsoup傳遞另一個URL,如果它無法連接到特定的URL。與此jsoup相關的還會在連接URL時花費太多時間來拋出錯誤。爲此,我已經把.timeout(100 * 1000)選項。但是,我想知道是否有一種方法可以傳遞給另一個URL,如果現在的嘗試時間過長?
在此先感謝。
Thanks @Joel Min! –