"Jsoup Learning Rites" loading a document from a URL

Source: Internet
Author: User

There is a problem

You need to get and parse an HTML document from a Web site and find the relevant data in it. You can use the following workaround:


How to use Jsoup.connect(String url) :

Document doc = Jsoup.connect("http://example.com/").get();String title = doc.title();

connect (String URL)   method creates a new  connection , and  get ()   gets and analyzes an HTML file. If an error occurs when getting HTML from this URL, IOException is thrown and should be handled appropriately.

connection   Interface also provides a method chain to resolve special requests, as follows:

document doc = Jsoup.connect (" http://example.com "). Data (" Query "," Java "). useragent (" Mozilla "). Cookie ("auth", "token"). Timeout (+). Post ();  

This method only supports Web URLs ( http and https protocols); If you need to load from a file, you can use it parse(File in, String charsetName) instead.

"Jsoup Learning Rites" loading a document from a URL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.