From 29b9ed551c3cb3f20a46d9dfa28cb81403c08dc7 Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:05:05 +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 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/py/IPTV搜索引擎采集.py b/py/IPTV搜索引擎采集.py index 7bc4c55..ac3a5bd 100644 --- a/py/IPTV搜索引擎采集.py +++ b/py/IPTV搜索引擎采集.py @@ -70,10 +70,14 @@ def get_tonkiang(keyword): try: status = div.xpath('./div[3]/div/text()')[0] if "暂时失效" not in status: - ip = div.xpath('./div[1]/a/b/text()')[0].strip() - if via_tonking(ip): - result_urls.append(f'http://{ip}') - except (IndexError, ValueError): + # 尝试提取IP地址或域名 + ip_or_domain = div.xpath('./div[1]/a/b/text()')[0].strip() + # 解析IP地址或域名 + parsed_url = urlparse(f'http://{ip_or_domain}') + if parsed_url.scheme and parsed_url.netloc: + if via_tonking(parsed_url.geturl()): + result_urls.append(parsed_url.geturl()) + except (IndexError, ValueError, AttributeError): continue return result_urls except Exception as e: