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);
|
}
|
|
}
|