Home >Java >javaTutorial >What is Jsoup? What is the usage of Jsoup?

What is Jsoup? What is the usage of Jsoup?

不言
不言Original
2018-09-26 14:27:357292browse

The content of this article is about what is Jsoup? What is the usage of Jsoup? It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

What is jsoup?

I won’t talk about jsoup. I will introduce Baidu in detail or go to the official website to check.

How to use jsoup?

The operations of jsoup and jquery are similar. Let’s use them briefly.

Using jsoup probably involves the following steps:

1. Get the entire html document

2. Use the selector to get the set of data nodes that need to be crawled

3. Loop through and use the selector to obtain the corresponding data

Instance

##This is the project structure For an ordinary test project, you need to import the jsoup-x.xx.x.jar package and then create an entity class.

Let’s take this crooked joke.

Each joke corresponds to a div.

Create a test main method to obtain the corresponding entire html page through the Jsoup.conect(url).get(); method

Then pass the select method. The select method is similar to the jquery selector. You can select tags through ., #, attributes, etc.

Note: The selector here selects all nodes with class xh, which is the set of all joke nodes above

##Then loop the node collection

Then get the corresponding node according to the class attribute of the node and then get the node text with the text() method. Then run the output.

Attached are the running results:

jsoup is very playable, including Chinese New Year, festivals, and train tickets. That’s it for the brief introduction.

The above is the detailed content of What is Jsoup? What is the usage of Jsoup?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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