使用wget从Google趋势中提取csv

时间:2009-10-09 16:38:44

标签: wget

我想使用wget下载Google Trends csv数据,但我对使用wget不熟悉。示例URL是:

http://www.google.com/insights/search/overviewReport?cat=71&geo=US&q=apple&date&cmpt=q&content=1&export=1

使用Web浏览器打开它,我检索预期的文件。要使用wget执行此操作,我尝试了以下命令:

wget "http://www.google.com/insights/search/overviewReport?cat=71&geo=US&q=apple&date&cmpt=q&content=1&export=1" -O report.csv

导致以下结果:

<html><head><title>Redirecting</title>
<meta http-equiv="refresh" content="0; url=&#39;http://www.google.com/insights/search#content=1&amp;cat=71&amp;geo=US&amp;q=apple&amp;date&amp;cmpt=q&#39;"></head>
<body bgcolor="#ffffff" text="#000000" link="#0000cc" vlink="#551a8b" alink="#ff0000"><script type="text/javascript" language="javascript">
    location.replace("http://www.google.com/insights/search#content\x3d1\x26cat\x3d71\x26geo\x3dUS\x26q\x3dapple\x26date\x26cmpt\x3dq")
  </script></body></html>

我的第一个猜测是wget无权使用正确的身份验证访问Cookie。

任何人

1 个答案:

答案 0 :(得分:2)

您收到重定向消息。 location.replace位中的网址,您从Google获得的有效index.html就是您第二次拨打wget时的该网址。

您可能根本没有下载csv数据的正确URL。有关如何使用下载程序“点击”CGI界面的工作示例,请查看R包中的tseries get.hist.quote()

编辑:以下是get.hist.quote()的作用:

R> IBM <- get.hist.quote("IBM")
trying URL 'http://chart.yahoo.com/table.csv?s=IBM&a=0&b=02&c=1991&d=9&e=08&f=2009&g=d&q=q&y=0&z=IBM&x=.csv'
Content type 'text/csv' length unknown
opened URL
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... ......
downloaded 236 Kb

R>

您可以直接点击相同的网址,如您可以学习的代码所示。如果您需要cookie,您可能需要查看Duncan TL的代码才能访问Google Docs等。