1

次の URL を Python に読み込もうとしています。

http://www.google.com/trends/fetchComponent?q=nepal&cid=TIMESERIES_GRAPH_0&export=3

コードで:

trend_url = 'http://www.google.com/trends/fetchComponent?q=nepal&cid=TIMESERIES_GRAPH_0&export=3'        
response = urllib2.urlopen(trend_url)
the_page = response.read()

the_page の結果の値は、理由がわかりませんが、エラー ページです。

更新:この問題は認証の問題に関連していると思います: ブラウザーのシークレット ウィンドウでリンクを開こうとすると、エラー ページも返されます。

4

2 に答える 2

1

使用するrequests

import requests
a = requests.get('http://www.google.com/trends/fetchComponent?q=nepal&cid=TIMESERIES_GRAPH_0&export=3')
a.text

u'// Data table response\ngoogle.visualization.Query.setResponse({"version":"....


あなたの例をテストしましたが、うまくいきます。

于 2015-05-03T10:02:22.320 に答える