Python爬虫时遇到问题:
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
我将源码发给大家,请大家帮忙解决!
import requests
import re
import json
import pprint
url = 'https://www.bilibili.com/video/BV13Q4y1N734?spm_id_from=333.337.search-card.all.click%27
def get_video(url):
headers = {
'referer': 'https://www.bilibili.com/',
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.62'
}
response = requests.get(url=url, headers=headers)
return response
def get_video_info(url):
response = get_video(url)
print(response)
title = '【AMV-柯南】全员高燃混剪,你准备好了吗'
# print(response)
html_data = re.findall('<script>window.__playinfo__(.*?)</script>', response.text)[0]
print(pprint.pprint(html_data))
json_data = json.loads(html_data)
# print(pprint.pprint(json_data))
get_video_info(url)