我想从我通过代码创建的网址下载Google趋势数据.当这些URL放入浏览器(我使用firefox)时会显示一个保存提示,我可以选择在查看浏览器时打开或保存文件.但是,我希望通过代码包含Google趋势数据的相同.csv文件,我被困住了.
这是我的代码创建的链接之一:[提示下载,但是是Google]
我有这个链接的两个问题,它要么下载带有中文字符的.csv文件(我相信已损坏?),要么下载一些HTML(如下所示).当HTML保存为HTML文件并运行时,它会将我带到Google趋势主页,其中包含看似无用的URL:
https://www.google.com/trends/#geo=US&date=now+7-d&cmpt=q&q=debt&hl=en-US&content=1
<html><head><title>Redirecting</title>
<script type="text/javascript" language="javascript">
// Accessing window.external members can cause IE to throw exceptions.
// Any code that acesses window.external members must be try/catch wrapped
/** @preserveTry */
try {
if (top == self) {
if (window.gtbExternal) {
window.gtbExternal.setM();
} else {
window.external.setM();
}
}
}
catch(err) {
}
</script>
<meta http-equiv="refresh" content="0; url='http://www.google.com/trends#geo=US&date=now+7-d&cmpt=q&q=debt&hl=en-US&content=1'">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000cc" vlink="#551a8b" alink="#ff0000"><script type="text/javascript" language="javascript">
location.replace("http://www.google.com/trends#geo\x3dUS\x26date\x3dnow+7-d\x26cmpt\x3dq\x26q\x3ddebt\x26hl\x3den-US\x26content\x3d1")
</script></body></html>
Run Code Online (Sandbox Code Playgroud)
另外,这里是我用来下载.csv文件的代码,基本的WebClient下载方法,字符串url可以用上面的URL代替.
public static void Download(string url) …Run Code Online (Sandbox Code Playgroud)