我正在学习从链接中获取json数据并稍后使用该数据。但我得到的错误:“RuntimeError:在调用一个Python对象最大递归深度超过”试图从Python使用Python获取json数据
这里是我的代码:
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())
请看我编辑的问题,新c ode返回json数据,但现在我想在数据内部添加一些标签,我该怎么做? –
标签?你的json中的标签是什么意思? –
数据是json格式,但里面有html代码。我需要检索。 –