From e89de9319d8f771f8e53cb5f876d06465a580c57 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 02 八月 2021 18:23:22 +0800 Subject: [PATCH] kafka日志集成 --- src/main/java/com/yeshi/buwan/util/video/shortvideo/TencentWebUtil.java | 77 +++++++++++++++++++++++++++++++++++--- 1 files changed, 70 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/util/video/shortvideo/TencentWebUtil.java b/src/main/java/com/yeshi/buwan/util/video/shortvideo/TencentWebUtil.java index 535c2b4..7ff10f1 100644 --- a/src/main/java/com/yeshi/buwan/util/video/shortvideo/TencentWebUtil.java +++ b/src/main/java/com/yeshi/buwan/util/video/shortvideo/TencentWebUtil.java @@ -1,8 +1,5 @@ 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; @@ -10,13 +7,60 @@ 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 class TencentWebVideoInfo { + private String playUrl; + private String id; + private String title; + private String picture; + private String duration; + + public String getPlayUrl() { + return playUrl; + } + + public void setPlayUrl(String playUrl) { + this.playUrl = playUrl; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getPicture() { + return picture; + } + + public void setPicture(String picture) { + this.picture = picture; + } + + public String getDuration() { + return duration; + } + + public void setDuration(String duration) { + this.duration = duration; + } + } public static Map<String, String> parseParams(String url) { @@ -37,7 +81,15 @@ } - public static void getVideoList(Map<String, String> params, int page) throws Exception { + /** + * 鑾峰彇鐭棰戝垪琛� + * + * @param params + * @param page + * @return + * @throws Exception + */ + public static List<TencentWebVideoInfo> getVideoList(Map<String, String> params, int page) throws Exception { if (params == null) throw new Exception("鍙傛暟涓虹┖"); int pageSize = 30; @@ -53,6 +105,8 @@ String result = HttpUtil.get(url, params, headers); Document document = Jsoup.parse(result); Elements els = document.getElementsByClass("list_item"); + + List<TencentWebVideoInfo> list = new ArrayList<>(); for (int i = 0; i < els.size(); i++) { Element ele = els.get(i); String href = ele.getElementsByTag("a").get(0).attr("href"); @@ -63,12 +117,21 @@ picture = picture.startsWith("http") ? picture : "https:" + picture; String duration = ele.getElementsByClass("figure_caption").get(0).ownText(); System.out.println(duration); - } + TencentWebVideoInfo videoInfo = new TencentWebVideoInfo(); + videoInfo.setDuration(duration); + videoInfo.setId(id); + videoInfo.setPicture(picture); + videoInfo.setPlayUrl(href); + videoInfo.setTitle(title); + list.add(videoInfo); + } + return list; } 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); + List<TencentWebVideoInfo> videoInfos = getVideoList(parseParams("https://v.qq.com/channel/ent?_all=1&channel=ent&iarea=2&itype=-1&listpage=1&sort=40"), 1); + System.out.println(videoInfos); } } -- Gitblit v1.8.0