Hey I've just started to use Python 3.8 and I get bug for the last line. It works perfectly on python 3.6 how cam I make it work on Python 3.6?
in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: 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)
maybe in
python 3.8
, therequests
lib isnot handling the empty response
and its coded to raise an error when its empty.this error:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
is because the json response is
empty
, its avoid
string. ---->b''
(i didnt see the json, but i assume its empty and thats why its raising error)
from my experience:
out