0
我想写一个脚本,将搜索字符串在谷歌,循环和迭代字符串中的数字,并打印顶部的链接。我有这样的:使用Python来搜索字符串,其中数字迭代
import urllib.parse
import urllib.request
import json as m_json
for x in range(3, 5):
query = '"Amazon Best Sellers Rank: #' + str(x) + ' in Kitchen & Dining": Amazon.com'
query = urllib.parse.urlencode ({ 'q' : query })
response = urllib.request.urlopen ('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&' + query).read().decode()
json = m_json.loads (response)
results = json [ 'responseData' ] [ 'results' ]
for result in results:
title = result['title']
url = result['url'] # was URL in the original and that threw a name error exception
print (title + '; ' + url)
我得到这个错误: “类型错误: 'NoneType' 对象不是标化的” 第10行,结果= ...