[Python] 纯文本查看 复制代码 import requests
import re
import json
def fin_data(_url):
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
}
try:
get_url = requests.get(url=_url, headers=headers)
get_url.raise_for_status()
return get_url.text
except requests.RequestException as e:
print(f"请求失败: {e}")
return None
def extract_and_process_content(content):
# 使用正则表达式提取部分内容
pattern = re.compile(r'"part":"([^"]+)"')
matches = pattern.findall(content)
def decode_unicode(text):
return json.loads('"' + text + '"')
# 打印提取的并转换后的内容
for match in matches:
decoded_content = decode_unicode(match)
print(decoded_content)
if __name__ == '__main__':
url = 'https://www.bilibili.com/video/BV1uw411j7wh' # 替换为实际的网页链接
webpage_content = fin_data(url)
if webpage_content:
extract_and_process_content(webpage_content)
|