[Jsoup Learning Etiquette] Parse an HTML string_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:48:27
Original
1208 people have browsed it

There is a problem

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

Solution

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);
Copy after login

Description

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.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template