嘿,我刚开始使用 Python 3.8,最后一行出现错误。它在 python 3.6 上完美运行我如何让它在 Python 3.6 上运行?
在 raw_decode 从 None json.decoder.JSONDecodeError 中引发 JSONDecodeError("Expecting value", s, err.value): Expecting value: line 1 column 1 (char 0)
import requests
import urllib.request, urllib.parse
from bs4 import BeautifulSoup
import json
user = "travel.like.this"
url = 'https://www.instagram.com/' + user
req = urllib.request.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36')
html = urllib.request.urlopen(req).read()
response = BeautifulSoup(html, 'html.parser')
jsonObject = response.select("body > script:nth-of-type(1)")[0].text.replace('window._sharedData =','').replace(';','')
data = json.loads(jsonObject)