Problem Description:
When using Jsoup to crawl other site data, it is found that class is a multiple choice with spaces, and if you use Doc.getelementsbyclass ("Class value"), this method gets the data you want.
The crawl Site page structure is as follows:
The DIV for the article List is: <div class= "AM-CF inner_li inner_li_abtest" ></div>
We can see that the value of its class is: AM-CF inner_li inner_li_abtest. With a space. Multi-valued.
If we still use Getelementsbyclass () This method to obtain, it is not obtained. The eclipse break points are as follows:
You can see the length of the obtained value size=0. No data was obtained.
After searching, the solution was discovered: the Getelementsbyclass () method is not used, and other methods can be used.
First on success:
We can see that the length of the data is size=20. The description gets the data.
The following explains the Select method using:
Elements Org.jsoup.nodes.Element.select (String cssquery)
The style selector.
View Source:
We know this can be multiple.
In our case, we used the following: Div.am-cf.inner_li.inner_li_abtest. Why do you write this?
To view the page structure in which you want to crawl articles:
?
Now you understand why it's so used.
Edith Id:kaigejava
Personal website: www.kaigejava.com
Edith Website address: http://kaigejava.com/article/detail/121
Java crawler problem two: Using Jsoup crawl data class selector hollow lattice multi-choice how to solve