简体   繁体   中英

I am trying extract data from website using request and bs4 python module. when i try to access this code, got below error message to json

capcha2 = requests.post(url=url1,headers=headers3,data=payload1)
print(capcha2)
cap = json.loads(capcha2.text)
captcha_status = cap['required']
print(captcha_status)

when i try to load value to json, got below error message.

Traceback (most recent call last):
  File "C:\Users\Madeena\PycharmProjects\pythonProject\pythonProject2\ahamed3.py", line 39, in <module>
    cap = json.loads(capcha2.text)
  File "C:\Users\Madeena\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Madeena\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\Madeena\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 tried capcha2 = requests.post(url=url1,headers=headers3,data=payload1).json() got same error message

Method text for response can return json or html. In your case, capture2.text most likely returns html and because of this, json.loads() gives an error that it cannot parse this string in json. Use capture2.json() in the same way as after the get request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM