HTML string from user input, a file or a website, you may need to parse it and get its content, or verify whether its format is complete, or want to Modify it. what to do? jsonu can help you solve these problems easily
Use the static Jsoup.parse(String html) method or Jsoup.parse(String html, String baseUri) sample code:
String html = "<html><head><title>First parse</title></head>" + "<body><p>Parsed HTML into a doc.</p></body></html>";Document doc = Jsoup.parse(html);
parse(String html, String baseUri) This method can parse the input HTML into a new document (Document). The parameter baseUri is used to convert the relative URL into an absolute URL. And specify which website to get the document from. If this method is not applicable, you can use the parse(String html) method to parse into an HTML string as in the example above. .
As long as the parsed string is not an empty string, a well-structured document containing (at least) a head and a body element will be returned.
Once you have a Document, you can use the appropriate methods in Document or the methods in its parent classes Element and Node to obtain relevant data.