You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
2.4 KiB
41 lines
2.4 KiB
2 months ago
|
import requests
|
||
|
import re
|
||
|
|
||
|
def main():
|
||
|
# 定义请求头和 Cookie
|
||
|
headers = {
|
||
|
'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',
|
||
|
'cookie': 'buvid3=C1C1F447-BE4B-207B-2957-83F2A71759A059661infoc; b_nut=1702126959; i-wanna-go-back=-1; b_ut=7; _uuid=A1D1B10B10-2CF10-E524-9184-1071108C67B4E1064260infoc; enable_web_push=DISABLE; buvid4=5317C42D-F53F-8ADA-D1A4-10ED5A8CF36360134-023120913-; rpdid=|(u)luk)~u|l0J\'u~|kku|YkJ; buvid_fp_plain=undefined; DedeUserID=503618475; DedeUserID__ckMd5=0191b9f7decce9ef; header_theme_version=CLOSE; CURRENT_FNVAL=4048; PVID=1; FEED_LIVE_VERSION=V_DYN_LIVING_UP; CURRENT_QUALITY=80; fingerprint=494d7e3b36301c3a79f8e9874737c192; buvid_fp=494d7e3b36301c3a79f8e9874737c192; home_feed_column=5; browser_resolution=1528-738; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjY3NDUwMjAsImlhdCI6MTcyNjQ4NTc2MCwicGx0IjotMX0.eMwpvZWiFlweKrmxccHjMI_iLBtXhkjCTiGo47ZzSYo; bili_ticket_expires=1726744960; SESSDATA=83336e6b%2C1742037821%2C360f4%2A92CjAH43lV7rav7Ckt21G7pofPKHP90eY8UWnZbAt07TaYyt5UEqN4ePWE_NCr5lh3vfYSVkJoSzBzNldWOFZWUEZJZ2Y3YnY0dXZZWmllcXhUMlpDT1RhVk4xYldiZ3NRMG9XVnZpUnk4SWN6UHNLUUx3cDBsNkxUMHRHajZ2WGlkak5MVUFTX1RBIIEC; bili_jct=9406239f74c298cb8651019f52e42523; sid=7uv2rrbi; b_lsid=8BA3B5CC_191FF98AD70; bp_t_offset_503618475=978100787878035456; bsource=search_google'
|
||
|
}
|
||
|
|
||
|
# 读取 cid.txt 文件中的 CID 列表
|
||
|
with open("cid.txt", "r") as cids_file:
|
||
|
cids = [cid.strip() for cid in cids_file.readlines()]
|
||
|
|
||
|
# 存储弹幕内容的列表
|
||
|
danmu_content_list = []
|
||
|
|
||
|
# 遍历 CID 列表
|
||
|
for cid in cids:
|
||
|
url = f"https://comment.bilibili.com/{cid}.xml"
|
||
|
# 发送 GET 请求
|
||
|
response = requests.get(url=url, headers=headers)
|
||
|
response.encoding = 'utf-8'
|
||
|
# 提取弹幕数据
|
||
|
danmu_content = re.findall(r'<d p=".+?">(.+?)</d>', response.text)
|
||
|
# 添加弹幕内容到列表
|
||
|
danmu_content_list.extend(danmu_content)
|
||
|
|
||
|
# 打印弹幕内容的列表
|
||
|
print("完成弹幕内容的提取")
|
||
|
print(danmu_content_list)
|
||
|
|
||
|
# 将弹幕内容写入弹幕.txt文件
|
||
|
with open("弹幕.txt", "w", encoding="utf-8") as f:
|
||
|
for danmu in danmu_content_list:
|
||
|
f.write(danmu)
|
||
|
f.write('\n') # 添加换行符
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|