4. Load a Document from a URL
来源:百度文库 编辑:神马文学网 时间:2024/07/08 20:42:51
Load a Document from a URL
Problem
You need to fetch and parse a HTML document from the web, and find data within it (screen scraping).
Solution
Use the Jsoup.connect(String url)
method:
Document doc = Jsoup.connect("http://example.com/").get();
String title = doc.title();
Description
The connect(String url)
method creates a new Connection
, and get()
fetches and parses a HTML file. If an error occurs whilst fetching the URL, it will throw an IOException
, which you should handle appropriately.
The Connection
interface is designed for method chaining to build specific requests:
Document doc = Jsoup.connect("http://example.com") .data("query", "Java")
.userAgent("Mozilla") .cookie("auth", "token") .timeout(3000) .post();
This method only suports web URLs (http
and https
protocols); if you need to load from a file, use the parse(File in, String charsetName)
method instead.
4. Load a Document from a URL
5. Load a Document from a File
Words From a Father
Words from A Loving Father
Document a package using Javadoc - Real's Java How-to
6. Use DOM methods to navigate a document
Create a map from a published Google Spreadsheet
Using a Doc/View exported from a dynamically ...
双语:From A to Z 生活从A到Z
mercantilism: Definition and Much More from A...
A Message from Ancestor Quan Yin
Flightless bird , a perfect song from Twilight
Inspirational Tips and Tools from a Designer
A New Look from Borrowed Time
胡檬??直销业需要一场公开的听证会??url=http://www.lcr88.com/A...
赫德森:论如何应对当前世界金融危??url=http://www.wyzxsx.com/A...
How To Create A RSS Feed From Any Web Page
Redirect the Enter key from a Windows Forms T...
Extract private key and certificate from a PKCS12 file
From China to Panama, a Trail of Poisoned Med...
From China to Panama, a Trail of Poisoned Med...2
From China to Panama, a Trail of Poisoned Med...3
From China to Panama, a Trail of Poisoned Med...4
From China to Panama, a Trail of Poisoned Med...5