我正在使用 Wolfram Simple API,结果它会生成一个图像。我想在图像视图中显示该图像,但问题是我无法获取图像的 URL。我搜索了很多,但什么也找不到。任何人都可以帮助我并指导我如何获取结果图像的网址吗?
下面是一个通过 wolframalpha 找到 Natalie Portman 的照片的示例:
http://api.wolframalpha.com/v2/query?appid=DEMO&input=natalie%20portman&includepodid=Image:PeopleData&output=json
此请求专门请求仅返回映像 pod(通过 JSON(。
结果:
{
"queryresult": {
"success": true,
"error": false,
"numpods": 1,
"datatypes": "People",
"timedout": "",
"timedoutpods": "",
"timing": 1.489,
"parsetiming": 0.139,
"parsetimedout": false,
"recalculate": "",
"id": "MSP",
"host": "http://www5a.wolframalpha.com",
"server": "40",
"related": "http://www5a.wolframalpha.com",
"version": "2.6",
"pods": [
{
"title": "Image",
"scanner": "Data",
"id": "Image:PeopleData",
"position": 100,
"error": false,
"numsubpods": 1,
"subpods": [
{
"title": "",
"imagesource": "http://en.wikipedia.org/wiki/File:Natalie_Portman_at_TIFF_2009.jpg",
"img": {
"src": "http://www5a.wolframalpha.com",
"alt": "",
"title": "",
"width": 101,
"height": 150
},
"plaintext": ""
}
]
}
],
"sources": {
"url": "http://www.wolframalpha.com/sources/PeopleDataSourceInformationNotes.html",
"text": "People data"
}
}
}
例如,要使用python获取URL:
image_url = json_result['queryresult']['pods'][0]['subpods'][0]['imagesource']
print(image_url)
image_url:
http://en.wikipedia.org/wiki/File:Natalie_Portman_at_TIFF_2009.jpg
http://en.wikipedia.org/wiki/File:Natalie_Portman_at_TIFF_2009.jpg
对于 Wolfram Simple API,您必须将 url 输出直接传递给图像。
http://api.wolframalpha.com/v1/simple?appid=DEMO&i=What+airplanes+are+flying+overhead%3F
您可以在此处参考工作示例:
var url = 'http://api.wolframalpha.com/v1/simple?appid=DEMO&i=What+airplanes+are+flying+overhead%3F';
$(document).ready(function(){
$.ajax({
url : url,
}).always(function(){
$("#IMAGE_ID").attr("src", url);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<img id='IMAGE_ID'>
</body>