我有一个代码可以从必应搜索中获取网址。
import requests
URL = "https://mykey:mykey@api.datamarket.azure.com/Bing/Search/Web?$format=json&Query='query'"
API_KEY = 'mykey'
query = "JohnDalton"
def request(query, **params):
query = ('%27'+query+ '%27')
r = requests.get(URL % {'query': query}, auth=('', API_KEY))
print r.content
return r.json()['d']['results']
r = request("JohnDalton")
print r[0]['Url']
该脚本仅获取与我放入 url 的“查询”相关的 url,即使我尝试用行中的可变查询替换该值;
r = requests.get(URL % {'query': query}, auth=('', API_KEY))
为什么它不替换值?