0

我正在使用 Bing cse 在我的程序中接收信息,但我无法处理整个 bing 搜索数据。

有一个json格式的例子:

{u'Web': [{
    u'Description': u"Discription", 
    u'DisplayUrl': u'DisplayedUrl', 
    u'ID': u'Id', 
    u'Title': u'Title', 
    u'Url': u'Url', 
    u'__metadata': {
        u'type': u'WebResult', 
        u'uri': u"https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/ExpandableSearchResultSet(guid'XXXXX')/Web?$skip=0&$top=1"
    }
}]}

我有 DisplayUrl、Title、描述,但我不知道如何获取查询的 sub_title。sub_title 是标题下方的简短描述(并不总是出现)

“真实”必应搜索中的搜索结果显示方式如下:

标题
DisplayUrl
Sub_Title
描述

4

1 回答 1

0

Assuming you saved that structure as the variable foo, the following python code will iterate over the list of items (which you only gave one example of), and print out the values for each item:

for item in foo.get(u'Web', []):  # Iterate over the list under the dictionary key "Web"
    print item.get(u'Title'), item.get(u'DisplayUrl'), item.get(u'Sub_Title'), item.get(u'Description')

Title DisplayedUrl None Discription

You will notice that item.get(u'Sub_Title') will return None in this case, but would return valid data if the dictionary contains that key.

于 2013-11-12T22:27:46.613 回答