在谷歌浏览器上,我们可以通过点击“下载.csv文件”按钮来搜索关键字,下载该结果。 我编码的过程在多个关键字上运行。从代码下载csv文件
当我从谷歌洞察下载.csv
文件并在记事本中打开它时,我得到这种格式。
byte[] csv = client.DownloadData(url);
File.WriteAllBytes(path, csv);
我得到这样的格式:
Web Search Interest: hockey
Alabama (United States); Alaska (United States); Arizona (United States); Arkansas (United States); California (United States)
2004 - present
Interest over time
Week,Alabama,Alaska,Arizona,Arkansas,California
2004-01-04 - 2004-01-10,0,41,9,0,5
2004-01-11 - 2004-01-17,10,29,9,0,5
2004-01-18 - 2004-01-24,5,37,8,0,5
2004-01-25 - 2004-01-31,7,20,8,0,5
2004-02-01 - 2004-02-07,6,31,9,0,5
2004-02-08 - 2004-02-14,8,31,8,0,6
2004-02-15 - 2004-02-21,4,36,9,0,5
2004-02-22 - 2004-02-28,4,27,7,0,5
2004-02-29 - 2004-03-06,10,26,7,0,6
2004-03-07 - 2004-03-13,14,34,15,0,7
2004-03-14 - 2004-03-20,4,58,8,0,5
2004-03-21 - 2004-03-27,5,28,10,0,5
2004-03-28 - 2004-04-03,6,18,8,0,5
2004-04-04 - 2004-04-10,4,31,6,0,5
2004-04-11 - 2004-04-17,4,16,7,0,4
2004-04-18 - 2004-04-24,4,18,6,0,5
2004-04-25 - 2004-05-01,6,20,6,0,4
200
然而,当我使用的代码下载
Web Search Interest: football
Alabama (United States); Wisconsin (United States); Wyoming (United States)
2004 - present
Interest over time
Week Alabama Wisconsin Wyoming
2004-01-04 - 2004-01-10 14 10 0
2004-01-11 - 2004-01-17 10 7 7
2004-01-18 - 2004-01-24 10 7 7
2004-01-25 - 2004-01-31 10 7 7
2004-02-01 - 2004-02-07 13 8 7
2004-02-08 - 2004-02-14 9 6 0
2004-02-15 - 2004-02-21 7 5 0
2004-02-22 - 2004-02-28 8 5 0
2004-02-29 - 2004-03-06 5 4 0
2004-03-07 - 2004-03-13 5 5 0
2004-03-14 - 2004-03-20 7 4 6
2004-03-21 - 2004-03-27 8 4 7
2004-03-28 - 2004-04-03 7 5 7
2004-04-04 - 2004-04-10 5 3 8
2004-04-11 - 2004-04-17 7 4 8
2004-04-18 - 2004-04-24 7 5 8
2004-04-25 - 2004-05-01 7 6 6
但我的要求是要在第一时间拿到格式的代码,因为它是上传到需要第一种格式的地方。我的代码有什么问题,为什么格式会改变?
我使用的按钮后面这个网址:
<a title="" onclick="trends.PageTracker.trackSoph('exprt');" class="" href="http://www.google.com/insights/search/overviewReport?q=hockey&geo=US-AL%2CUS-AK%2CUS-AZ%2CUS-AR%2CUS-CA&cmpt=geo&content=1&export=1" id="exportLink"><div style="vertical-align: middle; float: left" class="goog-inline-block fs04img SPRITE_csv"></div><span style="text-decoration: underline; color: white; float: left;"> </span>Download as CSV</a>
代码,将该值赋给网址:
HtmlElement getDownloadLink = webBrowser1.Document.GetElementById("exportLink");
if (getDownloadLink != null)
{
string link = string.Empty;
link = getDownloadLink.GetAttribute("href");
downloadsheet(link, dir + textBox1.Text + filecounter + ".csv");
filecounter = filecounter + 1;
}
你确定你正在下载完全相同的路径吗?它看起来像下载链接版本可能传递参数告诉它是逗号分隔而不是制表符分隔。 – 2012-01-10 21:29:52
@ScottChamberlain请在结尾处看到我已更新的问题,谢谢 – confusedMind 2012-01-10 21:34:44
请同时包含为url分配值的代码 – 2012-01-10 21:37:10