【发布时间】:2019-05-08 17:46:44
【问题描述】:
我正在制作一个程序,可以在按特定国家代码搜索时在特定时间范围内(例如一天或一周)搜索 Bing 的文章数量。但是,我试图在列表中搜索每个查询,同时为每个查询重新运行程序并将每个查询的结果存储在另一个列表中,以便稍后分析数据。到目前为止的代码如下:
countries = ["AR","AU","BR","CA",...]
numbers = []
combinedList= []
subscription_key = "XXXXXXXXXXX"
assert subscription_key
search_url = "https://api.cognitive.microsoft.com/bing/v7.0/search"
search_term = "G20"
headers = {"Ocp-Apim-Subscription-Key" : subscription_key}
params = {"q": search_term, "cc": countries, "freshness":"Day"}
response = requests.get(search_url, headers=headers, params=params)
response.raise_for_status()
search_results = response.json()
totalRes = search_results["webPages"]['totalEstimatedMatches']
numbers.append(totalRes)
第 9 行的“cc”部分是您通常会尝试输入 2 位代码的地方,但我正在尝试单独执行所有操作。
提前谢谢你!
【问题讨论】:
标签: python json excel pandas bing