- INSTANT Jsoup How-to
- Pete Houston
- 112字
- 2021-08-20 16:52:35
How to do it...
- 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();
- If the input is a string, use:
- 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:
推薦閱讀