简体   繁体   中英

Using Jsoup to select classes and id

I am using this as an example

http://www.shopping.com/digital-camera/products?CLT=SCH&KW=digital+camera

In the linke above there is a class

<span class="numTotalResults">
  Results 1 - 40 of 1500&#43;
</span>

I got it using

Document query_result = Jsoup.connect("http://www.shopping.com")
                .data("CLT", "digital camera")
                .post();

but when I

System.out.println(query_result.select(".numTotalResults"));
System.out.println(query_result.select("#quickLookItem-1"));
System.out.println(query_result.select("[name=D0]"));

Nothing happens,

while

System.out.println(query_result);
System.out.println(query_result.select("span"));

clearly prints out the values

The selector seems to work only with div and span and anchor, but I can' select the classes or the id

Can someone help me?

Thanks

Edit:

It seems like the post did not go through. I don't quite understand why it didn't.

Instead of using POST request, try GET one:

Document query_result = Jsoup.connect("http://www.shopping.com/digital-camera/products?CLT=SCH&KW=digital+camera")
            .get();

Take a look how does this search works. It doesn't use POST method and it keeps all search parameters in a query string. After this small change your first select example will work well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM