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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.yeshi.buwan.util.rank;
 
import com.yeshi.buwan.util.HttpUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
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.*;
 
public class IqiyiRankUtil {
 
    public static Map<String, List<String>> getRank(int count) throws IOException {
        Document doc = Jsoup.connect("https://www.iqiyi.com/ranks1PCW/home").timeout(20000).get();
        Element root = doc.getElementsByClass("gc__page").get(0);
        Elements items = root.children();
        Map<String, List<String>> map = new HashMap<>();
        for (int i = 0; i < items.size(); i++) {
            Element item = root.child(i);
            if (item.hasClass("gc__tl1")) {
                List<String> totalRanks = new ArrayList<>();
                Elements cols = item.getElementsByClass("gc__grid").get(0).getElementsByClass("gc__col");
                for (Iterator<Element> its = cols.iterator(); its.hasNext(); ) {
                    Element col = its.next();
                    Elements names = col.getElementsByTag("a");
                    for (Iterator<Element> its1 = names.iterator(); its1.hasNext(); ) {
                        Element videoItem = its1.next();
                        String name = videoItem.getElementsByClass("rvi__tit1").attr("title");
                        totalRanks.add(name);
                    }
                }
                if(totalRanks.size()>count){
                    totalRanks = totalRanks.subList(0,10);
                }
                map.put("总榜", totalRanks);
            }
        }
 
        String url = "https://mesh.if.iqiyi.com/portal/pcw/rankList/comRankList?v=1&device=00d26e3cdde103b885d820f1545bd66a&auth=&uid=&ip=202.108.14.240&refresh=0&server=false";
        String result = HttpUtil.get(url);
        JSONObject resultJSON = JSONObject.fromObject(result);
        if (resultJSON.optInt("code") == 0) {
            JSONArray typesItem = resultJSON.optJSONObject("data").optJSONArray("items");
            for (int i = 0; i < typesItem.size(); i++) {
                String type = typesItem.optJSONObject(i).optString("name");
                if(type.contains("更多")){
                    continue;
                }
                List<String> tempList = new ArrayList<>();
                JSONArray cards = typesItem.optJSONObject(i).optJSONArray("cards");
                if (cards != null && cards.size() > 0) {
                    cards = cards.optJSONObject(0).optJSONArray("contents");
                    for (int c = 0; c < cards.size(); c++) {
                        String title = cards.optJSONObject(c).optString("title");
                        tempList.add(title);
                    }
                    if(tempList.size()>count){
                        tempList = tempList.subList(0,10);
                    }
                    map.put(type.replace("榜",""),tempList);
                }
 
            }
        }
 
        return map;
    }
 
    public static void main(String[] args) throws IOException {
        Map<String, List<String>> map = getRank(10);
        System.out.println(map);
    }
 
}