官术网_书友最值得收藏!

  • INSTANT Jsoup How-to
  • Pete Houston
  • 186字
  • 2021-08-20 16:52:35

How it works...

Basically, all the inputs will be given to the Jsoup class to parse.

For an HTML string, you just need to pass the HTML string as parameter for the method Jsoup.parse().

For an HTML file, there are three parameters inputted for Jsoup.parse(). The first one is the file object, which points to the specified HTML file; the second one is the character set of the file. There is an overload of this method with an additional third parameter, Jsoup.parse(File file, String charsetName, String baseUri). The baseUri URL is the URL from where the HTML file is retrieved; it is used to resolve relative paths or links.

For a URL, you need to use the Jsoup.connect() method. Once the connection succeeds, it will return an object, thus implementing the connection interface. Through this, you can easily get the content of the URL page using the Connection.get() method.

The previous example is pretty easy and straightforward. The results of parsing from the Jsoup class will return a Document object, which represents a DOM structure of an HTML page, where the root node starts from <html>.

主站蜘蛛池模板: 石景山区| 保山市| 京山县| 沅陵县| 娄底市| 三都| 双流县| 游戏| 临夏县| 旌德县| 大埔县| 泰宁县| 汾西县| 尼木县| 六盘水市| 高密市| 孟连| 盈江县| 漠河县| 铜梁县| 宁远县| 汝城县| 弥勒县| 堆龙德庆县| 志丹县| 五寨县| 德清县| 永济市| 云林县| 资源县| 保德县| 广州市| 朝阳区| 佛冈县| 平乐县| 探索| 泽普县| 永安市| 天台县| 德格县| 清水河县|