如何获取Wolfram API返回的图像的URL?

时间:2018-04-16 04:50:33

标签: image wolframalpha

我正在使用Wolfram Simple API,因此会生成图像。我想在imageview中显示该图像,但问题是我无法获取图像的网址。我搜索了很多但找不到任何东西。任何人都可以帮助我并指导我如何获取该网址的网址结果图片?

2 个答案:

答案 0 :(得分:0)

以下是通过wolframalpha找到Natalie Portman的照片的例子:

private boolean isPlaying;

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.actionbarlogic, menu);
    if (isPlaying) menu.removeItem(R.id.play_button);
    else menu.removeItem(R.id.pause_button);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.play_button:
            // Do what the play button should do here
            isPlaying = true;
            break;

        case R.id.pause_button:
            // Do what the pause button should do here
            isPlaying = false;
            break;
    }
    invalidateOptionsMenu();
    return true;
}

此请求专门请求返回图像窗格(通过JSON)。

结果:

http://api.wolframalpha.com/v2/query?appid=DEMO&input=natalie%20portman&includepodid=Image:PeopleData&output=json

使用python获取URL,例如:

{
    "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"
        }
    }
}

IMAGE_URL:

image_url = json_result['queryresult']['pods'][0]['subpods'][0]['imagesource']
print(image_url)

http://en.wikipedia.org/wiki/File:Natalie_Portman_at_TIFF_2009.jpg

答案 1 :(得分:0)

对于Wolfram Simple API,您必须将url输出直接传递给image。

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>
&#13;
&#13;
&#13;