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 回答
0

我认为有点晚了,但我认为谷歌这样做是为了保护他们的数据。您必须创建一个网页抓取,它将转到界面输入您想要的单词,它会生成页面/网址。这与生成的 URL 乍一看不同。

于 2019-06-14T01:07:57.330 回答