admin
2025-02-20 f537abe9f3646c739beaf15076246a2f71a347e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.yeshi.buwan.util.rank;
 
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
public class TencentRankUtil {
 
    public static Map<String, List<String>> getRank(int count) throws IOException {
        Document doc = Jsoup.connect("https://v.qq.com/biu/ranks/?t=hotsearch").timeout(20000).get();
        Element root = doc.getElementsByClass("mod_row_box").get(0);
        Elements items = root.getElementsByClass("mod_rank_figure");
        Map<String, List<String>> map = new HashMap<>();
        for (int i = 0; i < items.size(); i++) {
            Element item = items.get(i);
            String title = item.getElementsByClass("title").get(0).text();
            List<String> list = new ArrayList<>();
            Elements names = item.getElementsByClass("item");
            for (int j = 0; j < names.size(); j++) {
                Element name = names.get(j);
                String itemTitle = name.getElementsByTag("a").attr("title");
                list.add(itemTitle);
                if (list.size() >= count)
                    break;
            }
            map.put(title, list);
 
        }
        return map;
    }
 
    public static void main(String[] args) throws IOException {
        Map<String, List<String>> map = getRank(10);
        System.out.println(map);
    }
 
}