2017-10-11 9 views
0

私は、Pythonを使用してGoogle検索で何かをやろうとしている、と私はほとんどエラーレスをアップしていますこのコードを見つけましたが、私はエラーPythonのGoogle検索はTypeError

(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) 

答えて

0

Googleがクエリをブロックしようとすると、レスポンスは[なし]になり、コードは機能しません。 GoogleはCookieを管理し、あなたのIPを変更するには、プロキシのリストを使用して、より複雑なソリューションが必要になります結果こするWebに

など

ここでは、これをより正確な解決策を見つけるでしょう: Is it ok to scrape data from Google results?