package com.yeshi.buwan.util.tvlive;
|
|
import com.yeshi.buwan.domain.live.TVLiveChannel;
|
import com.yeshi.buwan.util.NumberUtil;
|
import com.yeshi.buwan.util.StringUtil;
|
import org.jsoup.Jsoup;
|
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Element;
|
import org.jsoup.select.Elements;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 搜视网
|
*/
|
public class TVSOUUtil {
|
|
public static List<TVLiveChannel.TVLiveProgram> getProgramList(String url) throws Exception {
|
String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36";
|
Document doc = Jsoup.connect(url).userAgent(userAgent).referrer(url).timeout(60000).get();
|
List<TVLiveChannel.TVLiveProgram> list = new ArrayList<>();
|
Element pgrow = doc.getElementsByClass("c_main_section").get(0).getElementsByClass("tab_nav").get(0).getElementsByTag("table").get(0);
|
Elements items = pgrow.getElementsByTag("tr");
|
for (int i = 0; i < items.size(); i++) {
|
list.add(parseProgram(items.get(i)));
|
}
|
|
return list;
|
}
|
|
|
private static TVLiveChannel.TVLiveProgram parseProgram(Element item) throws Exception {
|
String name = item.getElementsByTag("td").get(1).text().trim();
|
String time = item.getElementsByTag("td").get(0).text().trim();
|
|
if (StringUtil.isNullOrEmpty(name)) {
|
throw new Exception("节目名称为空");
|
}
|
if (!time.contains(":") || !NumberUtil.isNumeric(time.replace(":", ""))) {
|
throw new Exception("时间格式错误");
|
}
|
return new TVLiveChannel.TVLiveProgram(time, name);
|
}
|
|
public static void main(String[] args) throws Exception {
|
|
getProgramList("https://www.tvsou.com/epg/yangshi/");
|
|
|
}
|
|
|
}
|