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

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

How to do it...

  1. Create the Document class structure from Jsoup, depending on the type of input.
    • If the input is a string, use:
      String html = "<html><head><title>jsoup: input with string</title></head><body>Such an easy task.</body></html>";
      Document doc = Jsoup.parse(html);
    • If the input is from a file, use:
      try {
      File file = new File("index.html");
      Document doc = Jsoup.parse(file, "utf-8");
      } catch (IOException ioEx) {
          ioEx.printStackTrace();
      }
    • If the input is from a URL, use:
      Document doc = Jsoup.connect("http://www.example.com").get();
  2. Include the correct package at the top.
    import org.jsoup.Jsoup;
    import.jsoup.nodes.Document;
Note

The complete example source code for this section is in \source\Section01.

The API reference for this section is available at the following location:

http://jsoup.org/apidocs/org/jsoup/Jsoup.html

主站蜘蛛池模板: 鸡泽县| 三台县| 乡城县| 云霄县| 盘锦市| 威信县| 建阳市| 仪陇县| 土默特左旗| 团风县| 鹤庆县| 五指山市| 绥中县| 兰溪市| 萨迦县| 昂仁县| 广平县| 杂多县| 林口县| 集贤县| 伽师县| 平安县| 大城县| 都匀市| 莲花县| 肇东市| 天水市| 修水县| 德昌县| 墨竹工卡县| 甘肃省| 图木舒克市| 修武县| 宝兴县| 景宁| 扬中市| 武山县| 定边县| 桃源县| 兴和县| 广德县|