Update IPTV搜索引擎采集.py
This commit is contained in:
+11
-22
@@ -33,39 +33,28 @@ header = {
|
|||||||
import requests
|
import requests
|
||||||
from lxml import etree
|
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):
|
def via_tonking(url):
|
||||||
headers = {
|
headers = {
|
||||||
'Referer': 'http://tonkiang.us/hotellist.html',
|
'Referer': 'http://tonkiang.us/hotellist.html',
|
||||||
'User-Agent': header["User-Agent"],
|
'User-Agent': header["User-Agent"],
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
cities = ['北京市', '江苏省']
|
# 提取 IP 地址部分,去除协议
|
||||||
for city in cities:
|
ip_address = url.split("//")[-1]
|
||||||
# 提取 IP 地址部分,去除协议
|
response = requests.get(
|
||||||
ip_address = url.split("//")[-1]
|
url=f'https://tonkiang.us/hoteliptv.php?page=1&iphone1=%E5%8C%97%E4%BA%AC%E5%B8%82&code=',
|
||||||
response = requests.get(
|
headers=headers,
|
||||||
url=f'https://tonkiang.us/hoteliptv.php?page=1&iphone16={city}&code=',
|
timeout=10
|
||||||
headers=headers,
|
)
|
||||||
timeout=10
|
response.raise_for_status()
|
||||||
)
|
et = etree.HTML(response.text)
|
||||||
response.raise_for_status()
|
div_text = et.xpath('//div[@class="result"]/div/text()')[1]
|
||||||
et = etree.HTML(response.text)
|
return "暂时失效" not in div_text
|
||||||
div_text = et.xpath('//div[@class="result"]/div/text()')[1]
|
|
||||||
if "暂时失效" not in div_text:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"验证 IP 时发生错误: {e}")
|
print(f"验证 IP 时发生错误: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 从tonkiang获取可用IP
|
# 从tonkiang获取可用IP
|
||||||
def get_tonkiang(keyword):
|
def get_tonkiang(keyword):
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
Reference in New Issue
Block a user