Java crawler problem two: Using Jsoup crawl data class selector hollow lattice multi-choice how to solve

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.