ValueError:将html转换为json

时间:2018-04-23 22:50:21

标签: python json python-2.7

我在执行以下python脚本时遇到错误。 问题是将html输出转换为json。如果你帮我解决问题,将会非常有帮助。

import urllib2
import json`

url ='http://localhost:40102/cq/etc/replication/agents.author/publish- 
u11cmspu1.html'
username='admin'
password='admin'
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, username, password)``
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
pagehandle = urllib2.urlopen(url)
json_response=json.loads(pagehandle.read())
# output=json.load(pagehandle.read())
print json_response



ERROR :

Traceback (most recent call last):
File "./repQstatus.py", line 18, in <module>
json_response=json.loads(pagehandle.read())
File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python2.6/json/decoder.py", line 338, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

1 个答案:

答案 0 :(得分:0)

这里发生的是set I := {1, 2, 3, 4}; set J := {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; set K := {1, 2, 3, 4, 5, 6}; var d >=0; var x binary; CODE.txt, line 18 (offset 332): syntax error context: minimize Total_Cost: sum {i in I, j in J, k in K} >>> x[ <<< i,j,k] * d[i]; 的返回值返回一个python json库无法识别为JSON的字符串。

if(i+j==1){ 的响应中肯定会有JSON,但有些东西会阻止它被正确评估。