0
嘿,我試着用用Python谷歌搜索的東西,我發現這個代碼,大多出現無誤的,但我得到的錯誤Python的谷歌搜索類型錯誤
(TypeError: 'NoneType' object is not subscriptable)
和不知道是什麼去做。預先感謝您的幫助。
import urllib.request
import json as m_json
query = input ('Query: ')
query = urllib.parse.urlencode ({ 'q' : query })
response = urllib.request.urlopen ('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&' + query).read()
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)