JSoup检索URL不起作用 [英] JSoup Retrieve URL Not Working
本文介绍了JSoup检索URL不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have a URL and I use JSoup to retieve web page indicated by this url.
try{
doc = Jsoup.connect(url).timeout(5000).get();
}catch(IOException e){
e.printStackTrace();
}
但是我得到以下异常:
Exception in thread "main" java.lang.IllegalArgumentException: Must supply a valid URL
at org.jsoup.helper.Validate.notEmpty(Validate.java:102)
at org.jsoup.helper.HttpConnection.url(HttpConnection.java:48)
at org.jsoup.helper.HttpConnection.connect(HttpConnection.java:24)
at org.jsoup.Jsoup.connect(Jsoup.java:59)
推荐答案
检查以下内容:
- 您要将预期的URL传递给
url
变量. - URL的格式正确,可以肯定.
- You are passing intended URL to
url
variable. - The URL is well formed just to be doubly sure.
Jsoup的Validate.java中的方法notEmpty
检查Url是否为空.
The Method notEmpty
in Validate.java of Jsoup checks if the Url is not empty.
public static void notEmpty(String string) {
if (string == null || string.length() == 0)
throw new IllegalArgumentException("String must not be empty");
}
这篇关于JSoup检索URL不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文