附加题1代码文件1

main
pw4izm9rs 2 months ago
parent f3ef196c04
commit d50bb5b8bd

@ -0,0 +1,21 @@
import requests
import re
header = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0"}
url = "http://sports.news.cn/olympicparis2024/index.html"
response = requests.get(url=url, headers=header)
response.encoding = 'utf-8'
data = response.text
list1 = re.findall("blank'>(.*?)</a>",data)
list2 = re.findall('</a></div> <div data-swiper-parallax="-500" class="abs">(.*?)。',data)
content = []
content.extend(list1)
content.extend(list2)
print(content)
for i in content: # 遍历弹幕
with open('aoyun.txt', 'a', encoding='utf-8') as f: # 打开文件准备写入
f.write(i + '\n') # 写入弹幕
Loading…
Cancel
Save