【发布时间】:2016-08-28 06:36:06
【问题描述】:
我正在学习从链接中获取 json 数据并稍后使用该数据。但我收到错误:“RuntimeError:调用 Python 对象时超出最大递归深度”
这是我的代码:
import json
import requests
from bs4 import BeautifulSoup
url = "http://example.com/category/page=2&YII_CSRF_TOKEN=31eb0a5d28f4dde909d3233b5a0c23bd03348f69&more_products=true"
header = {'x-requested-with': 'XMLHttpRequest'}
mainPage = requests.get(url, headers = header)
xTree = BeautifulSoup(mainPage.content, "lxml")
newDictionary=json.loads(str(xTree))
print (newDictionary)
编辑:好的,我使用这个微小的变化得到了响应数据,这是新代码:
import json
import requests
from bs4 import BeautifulSoup
url = "http://example.com/category/page=2&YII_CSRF_TOKEN=31eb0a5d28f4dde909d3233b5a0c23bd03348f69&more_products=true"
header = {'x-requested-with': 'XMLHttpRequest'}
mainPage = requests.get(url, headers = header
print (mainPage.json())
【问题讨论】: