package com.yeshi.buwan.util.video.shortvideo;
|
|
import com.yeshi.buwan.util.StringUtil;
|
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 org.yeshi.utils.HttpUtil;
|
|
import java.net.URLDecoder;
|
import java.net.URLEncoder;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
public class TencentWebUtil {
|
|
|
public static Map<String, String> parseParams(String url) {
|
//清除参数
|
String param = null;
|
if (url.indexOf("?") > -1) {
|
param = url.substring(url.indexOf("?"));
|
}
|
if (!url.contains("v.qq.com")) {
|
return null;
|
}
|
String[] params = param.split("&");
|
Map<String, String> map = new HashMap<>();
|
for (String p : params) {
|
map.put(p.split("=")[0], URLDecoder.decode(p.split("=")[1]));
|
}
|
return map;
|
}
|
|
|
public static void getVideoList(Map<String, String> params, int page) throws Exception {
|
if (params == null)
|
throw new Exception("参数为空");
|
int pageSize = 30;
|
params.put("append", "1");
|
params.put("listpage", page + "");
|
params.put("offset", (page - 1) * pageSize + "");
|
params.put("pagesize", pageSize + "");
|
|
String url = "https://v.qq.com/x/bu/pagesheet/list";
|
Map<String, String> headers = new HashMap<>();
|
headers.put("referer", "https://v.qq.com/channel/ent");
|
headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36");
|
String result = HttpUtil.get(url, params, headers);
|
Document document = Jsoup.parse(result);
|
Elements els = document.getElementsByClass("list_item");
|
for (int i = 0; i < els.size(); i++) {
|
Element ele = els.get(i);
|
String href = ele.getElementsByTag("a").get(0).attr("href");
|
String id = ele.getElementsByTag("a").get(0).attr("data-float");
|
String title = ele.getElementsByTag("a").get(0).attr("title");
|
title = new String(title.getBytes("ISO-8859-1"), "UTF-8");
|
String picture = ele.getElementsByTag("img").get(0).attr("src");
|
picture = picture.startsWith("http") ? picture : "https:" + picture;
|
String duration = ele.getElementsByClass("figure_caption").get(0).ownText();
|
System.out.println(duration);
|
}
|
|
}
|
|
|
public static void main(String[] args) throws Exception {
|
getVideoList(parseParams("https://v.qq.com/channel/ent?_all=1&channel=ent&iarea=2&itype=-1&listpage=1&sort=40"), 1);
|
}
|
}
|