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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| import requests from bs4 import BeautifulSoup import re
# 1. 身份验证信息 auth_data = { "UserID": "0209170330290", "Lang": "", "SupportHD": "1", "NetUserID": "0209170330290@iptv.gd", "DHCPUserID": "0209170330290@iptv.gd", "Authenticator": "7D21702B6FA45DC20A4352BD1OOF9B694FBEFAAADD34B25FC818723AE666F7D0E6EE9B75AE7692A063041A58AC50DE673F03E178A576C195890F73D4F3C39A302FD7184CBDC91C0A0CE2AD077DA48E7A48BEC5F0BE97A15CDCAB45FF8725983F1F746501AF777AE74CB87D905E7E9E910C1A1E12FB1316689E5DD49D871EF76F", "STBType": "FIBERHOME_HG680KA", "STBVersion": "1.150150.13.2022v1", "conntype": "2", "STBID": "001005990016208092E98820115D2042", "templateName": "iptvsnmv3", "areaId": "86020", "userToken": "32F1583A459D7E48A6310D54FBC1CCCA", "userGroupId": "", "productPackageId": "", "mac": "58:19:2D:24:28:02", "UserField": "", "SoftwareVersion": "1.150150.13.2022v1", "IsSmartStb": "1", "desktopId": "", "stbmaker": "", "VIP": "", }
# 2. 用于身份验证的URL auth_url = "http://183.59.156.43:8082/EPG/jsp/ValidAuthenticationHWCTC.jsp" channel_list_url = "http://183.59.156.43:8082/EPG/jsp/getchannellistHWCTC.jsp"
# 3. 创建会话 session = requests.Session()
# 4. 发起身份验证请求,获取Cookie response = session.post(auth_url, data=auth_data) if response.status_code == 200: print("身份验证成功") else: print("身份验证失败") exit(1)
# 5. 获取频道列表页面 response = session.get(channel_list_url) if response.status_code == 200: print("成功获取频道列表页面") else: print("获取频道列表页面失败") exit(1)
# 6. 解析HTML并提取频道信息 html_content = response.text soup = BeautifulSoup(html_content, "html.parser") scripts = soup.find_all("script")
# 查找所有包含频道信息的脚本 m3u8_channels = "" regex = re.compile(r',?(.+?)="(.*?)"') zhujiang_channel = ""
for script in scripts: if "CTCSetConfig" in script.string: matches = regex.finditer(script.string) info = {} channel_name = "" channel_sdp = "" for match in matches: key, value = match.groups() if key == "ChannelName": channel_name = value if key == "ChannelSDP": channel_sdp = value
if channel_name: m3u8_channels += f'#EXTINF:-1 tvg-name="{channel_name}",{channel_name}\n' m3u8_channels += f"{channel_sdp}\n"
# 筛选出“广东珠江”频道 if channel_name == "广东珠江": zhujiang_channel = f'#EXTINF:-1 tvg-name="{channel_name}",{channel_name}\n{channel_sdp}\n'
# 7. 保存 IPTV.m3u8 文件 with open("IPTV.m3u8", "w", encoding="utf-8") as m3u8_file: m3u8_file.write(m3u8_channels) print("IPTV.m3u8 文件已生成")
# 8. 保存 zhujiang.m3u8 文件 if zhujiang_channel: with open("zhujiang.m3u8", "w", encoding="utf-8") as zhujiang_file: zhujiang_file.write(zhujiang_channel) print("zhujiang.m3u8 文件已生成") else: print("未找到“广东珠江”频道信息")
|