From 43a89ba37eeeb3ef5b34631d7bc8318bd062ddc8 Mon Sep 17 00:00:00 2001 From: pg7s85mrc <3224571700@qq.com> Date: Mon, 16 Sep 2024 22:52:22 +0800 Subject: [PATCH] ADD file via upload --- works_2.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 works_2.py diff --git a/works_2.py b/works_2.py new file mode 100644 index 0000000..5f3db65 --- /dev/null +++ b/works_2.py @@ -0,0 +1,31 @@ +import requests as res +import bs4 +from bs4 import BeautifulSoup +import re +#导入网址 +url = 'https://api.bilibili.com/x/v2/dm/wbi/web/seg.so?type=1&oid=500001646144543&pid=112943899411643&segment_index=1&pull_mode=1&ps=120000&pe=360000&web_location=1315873&w_rid=a7ec617df1c0828a97046a938e59a864&wts=1726493362' +#头部 +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" + #"Referer': 'https://www.bilibili.com/" + } +#b站访问要求cookie +cookies = { + 'SESSDATA':"b_nut=1655287595; buvid3=BF250087-55FD-D740-F149-152C712F432A94793infoc; buvid4=2F195046-6FB2-C0ED-84F3-CFE797B8DEEA94793-022061518-5IOzIX6vtHJ9FRL7o6i1zQ%3D%3D; CURRENT_BLACKGAP=0; buvid_fp_plain=undefined; DedeUserID=26136862; DedeUserID__ckMd5=f2772e0836b37b7d; LIVE_BUVID=AUTO8716595296112114; is-2022-channel=1; enable_web_push=DISABLE; header_theme_version=CLOSE; rpdid=|(u))kkYu||u0J'u~|JRuYRuJ; FEED_LIVE_VERSION=V_WATCHLATER_PIP_WINDOW2; _uuid=E293C3CE-5BA2-AA102-47A1-CAD1F6E712FB26442infoc; CURRENT_FNVAL=4048; hit-dyn-v2=1; CURRENT_QUALITY=112; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjY1ODU2NjIsImlhdCI6MTcyNjMyNjQwMiwicGx0IjotMX0.CsOd0CJGNhKRv6UunXKonpIkkO2qBz_p-Gw81mi4tpI; bili_ticket_expires=1726585602; SESSDATA=3f48a236%2C1741878463%2C15a29%2A92CjBaveekXDe5OQ_IwEae3xIQl4PGsZv8ExuVSsoPBtXBdi4FoS1NXu-XtKAQyRFkN90SVlZDQ1JmS0duZWN4NW9Ra0VQLW05ck5NRWs0MG05eW1KeGpCVVNlQTJQV0Jwb2lQTWxUNWZ0NGozYnRBZzBGYldiMXZCUXFPZVd3OW05QWtiYTFHeFRnIIEC; bili_jct=5780f62cf4b6afb7aee05c23729c89b4; sid=75357c50; fingerprint=21eff4f800f9e3be41201f47f1bf1477; buvid_fp=21eff4f800f9e3be41201f47f1bf1477; PVID=1; bsource=search_bing; b_lsid=71AD72B1_191F9A96CD1; bp_t_offset_26136862=977672485149343744; home_feed_column=5; browser_resolution=1442-740" +} +#发送请求 +response = res.get(url=url,headers=headers,cookies=cookies) +#解决乱码问题 +response.encoding = 'utf-8' + +#打印数据 +print(response.text) +#数据解析 +comment_list = re.findall('(.*?)',response.text) +print (comment_list) +#循环打印并输出结果到文本中 +for comment in comment_list: + with open('弹幕1.txt',mode = 'a',encoding = 'utf-8') as f: + f.write(comment) + f.write('\n') + print(comment)