使用 Jsoup.connect(String url)方法:
String url="http://www.baidu.com";
Document doc = Jsoup.connect(url).get();
illustrate
connect(String url)
methods to create a new one Connection
, and get()
get and parse an HTML file. If there is an error fetching the HTML from this URL, an IOException will be thrown and should be handled appropriately.
Connection
The interface also provides a method chain to resolve special requests, as follows:
String url="http://www.baidu.com";
Document doc = Jsoup.connect(url) .data("query", "Java") .userAgent("Mozilla") .cookie("auth", "token") .timeout(3000) .post();
This method only supports Web URLs ( http
and https
protocols); if you need to load from a file, use it parse(File in, String charsetName)
instead.