Update GAT.py
This commit is contained in:
@@ -19,18 +19,18 @@ output_file = 'gat.txt'
|
|||||||
|
|
||||||
keywords = ['凤凰卫视', '人间卫视', '香港卫视'] # 这里定义你的搜索关键词列表
|
keywords = ['凤凰卫视', '人间卫视', '香港卫视'] # 这里定义你的搜索关键词列表
|
||||||
output_file = 'gat.txt'
|
output_file = 'gat.txt'
|
||||||
|
|
||||||
with open(output_file, 'w', encoding='utf-8') as f:
|
with open(output_file, 'w', encoding='utf-8') as f:
|
||||||
for keyword in keywords:
|
for keyword in keywords:
|
||||||
url = f'http://tonkiang.us/?&iqtv={keyword}'
|
url = f'http://tonkiang.us/?&iqtv={keyword}'
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
# 使用BeautifulSoup解析网页内容并提取文本
|
|
||||||
soup = BeautifulSoup(response.text, 'html.parser')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
text_content = soup.get_text()
|
text_content = soup.get_text()
|
||||||
f.write(text_content + '\n')
|
f.write(text_content + '\n')
|
||||||
else:
|
else:
|
||||||
print(f'请求 {url} 失败,状态码:{response.status_code}')
|
print(f'请求 {url} 失败,状态码:{response.status_code}')
|
||||||
|
time.sleep(1) # 添加 1 秒的延迟
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
with open('gat.txt', 'r', encoding='utf-8') as infile:
|
with open('gat.txt', 'r', encoding='utf-8') as infile:
|
||||||
|
|||||||
Reference in New Issue
Block a user