Home > other >  With get success to obtain the content of a url, an error in the contents into a json
With get success to obtain the content of a url, an error in the contents into a json

Time:09-22

 
The import requests
The import json
The import sys
Reload (sys)
Sys. Setdefaultencoding (' utf-8)
R=requests. Get (" http://rlsbj.cq.gov.cn/zwgk_182/fdzdgknr/sydwgkzpxxgk/")
Print (r.s tatus_code)
Print (r.e ncoding)
Ct=r.h. eaders [' the content-type ']
Dic=json. Loads (r.c ontent. Decode ())
Print (dic)

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
200
ISO - 8859-1
Traceback (the most recent call last) :
The File "is the main. Py", line 21, in & lt; module>
Dic=json. Loads (r.c ontent. Decode ())
The File "/Library/Frameworks/Python framework Versions/2.7/lib/python2.7/json/set py", line 339, loads in
Return _default_decoder. Decode (s)
The File "/Library/Frameworks/Python framework Versions/2.7/lib/python2.7/json/decoder py", line 364, decode in
Obj, end=self. Raw_decode (s, independence idx=_w (s, 0). The end ())
The File "/Library/Frameworks/Python framework Versions/2.7/lib/python2.7/json/decoder py", line 382, in raw_decode
Raise ValueError (" No JSON object could be decoded ")
ValueError: No JSON object could be decoded
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Tip I want to convert data dictionary is not a json format

CodePudding user response:

Your code is python3, python 2.7 json is why?

The page is HTML, the need to parse HTML
  • Related