admin
2021-09-24 f788607ff771a47bc60d6a86e00b3433c40f3d2c
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
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/");
 
 
    }
 
 
}