嘿,我是 python 编程的新手。我有一个从 bing 搜索中获取 url 的程序。它应该在最后两行代码中打印 url。然而它给出了上面提到的错误。
import requests
URL = "https://mykey:mykey@api.datamarket.azure.com/Bing/Search/Web?$format=json&Query=%(query)s"
API_KEY = 'mykey'
def request(query, **params):
query = ('%27'+query+ '%27')
r = requests.get(URL % {'query': query}, auth=('', API_KEY))
print r.content
return [res['Url'] for res in r.json()['d']['results']]
r = request("Jason Bourne")
for res in r['d']['results']:
print res['Url']
错误是倒数第二行我该如何修复代码?
这是回溯
for res in r['d']['results']:
TypeError: list indices must be integers, not str