From 52e029f599128083991a329e7d0e0fa9d5efeec9 Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:41:11 +0800 Subject: [PATCH] =?UTF-8?q?Update=20IPTV=E6=90=9C=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E6=93=8E=E9=87=87=E9=9B=86.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/IPTV搜索引擎采集.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/py/IPTV搜索引擎采集.py b/py/IPTV搜索引擎采集.py index de2580b..e91567f 100644 --- a/py/IPTV搜索引擎采集.py +++ b/py/IPTV搜索引擎采集.py @@ -33,29 +33,39 @@ header = { import requests from lxml import etree + +# 假设header已经定义好,这里简单示例一个User-Agent +header = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" +} + def via_tonking(url): headers = { 'Referer': 'http://tonkiang.us/hotellist.html', 'User-Agent': header["User-Agent"], } try: - # 提取 IP 地址部分,去除协议 - ip_address = url.split("//")[-1] - response = requests.get( - #url=f'http://tonkiang.us/hoteliptv.php?s={ip_address}&c=false&y=false', - url=f'https://tonkiang.us/hoteliptv.php?page=1&iphone16={ip_address}&code=', - headers=headers, - timeout=10 - ) - response.raise_for_status() - et = etree.HTML(response.text) - div_text = et.xpath('//div[@class="result"]/div/text()')[1] - return "暂时失效" not in div_text + cities = ['北京市', '江苏省'] + for city in cities: + # 提取 IP 地址部分,去除协议 + ip_address = url.split("//")[-1] + response = requests.get( + url=f'https://tonkiang.us/hoteliptv.php?page=1&iphone16={city}&code=', + headers=headers, + timeout=10 + ) + response.raise_for_status() + et = etree.HTML(response.text) + div_text = et.xpath('//div[@class="result"]/div/text()')[1] + if "暂时失效" not in div_text: + return True + return False except Exception as e: print(f"验证 IP 时发生错误: {e}") return False + # 从tonkiang获取可用IP def get_tonkiang(keyword): data = {