G
G
GH0st_is_HAcker2021-10-04 20:44:35
Python
GH0st_is_HAcker, 2021-10-04 20:44:35

How to get json from a website using requests?

I wrote the code:

import requests
import json

url = "https://kugoo-russia.ru/electrosamokaty/dlya-dalnih-poezdok#button"
headers = {"accept": "text/plain, */*; q=0.01",
           "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36",
           "content-type": "text/html; charset=UTF-8"}

response = requests.get(url, headers=headers)
data_json = response.json()


It should take json data from the site
If this json is signed in the developer tool / network ?storepartuid=852286606495&...
Here is a link to the site: https://kugoo-russia.ru/electrosamokaty/dlya-dalni...

As a result, an error :
Traceback (most recent call last):
File "H:\Pycharm projects\EXPERIMENTS\EXP.py", line 10, in
data_json = response.json()
File "C:\Users\Andrew\AppData\Local\Programs\ Python\Python39\lib\site-packages\requests\models.py", line 910, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\Andrew\AppData\Local\Programs\ Python\Python39\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0) ).end())
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err .value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I think this error appeared due to the fact that json is not in the html code itself.

Maybe I should have added some more headers, but I I think the problem is something else

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-10-04
@GH0st_is_HAcker

If that this json is signed in developer tool/web ?storepartuid=852286606495&...

You need to send a request to storepartuid=852286606495&..., and you send to the main page

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question