From 4ac3b128156f42e8b204466f0d017cd32771baa1 Mon Sep 17 00:00:00 2001 From: pkjq8ohf2 <2100488276@qq.com> Date: Mon, 16 Sep 2024 15:12:50 +0800 Subject: [PATCH] ADD file via upload --- new.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 new.py diff --git a/new.py b/new.py new file mode 100644 index 0000000..355addd --- /dev/null +++ b/new.py @@ -0,0 +1,26 @@ +import io +import sys +import requests +import re +import json + +#将爬到的数据消除乱码 +sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') + +#''内填入网页url +url = 'https://api.bilibili.com/x/v1/dm/list.so?oid=1634922221' + +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' + } + +response = requests.get(url=url,headers=headers) +response.encoding = 'utf-8' + +#将需要获取的部分改为.*? +content_list = re.findall('(.*?)',response.text) +content_list = json.dumps(content_list,ensure_ascii=False,indent=2) + +#将爬取到的数据写为文本 +with open('output.txt', 'w', encoding='utf-8') as file: + file.write(content_list)