2012-01-10 91 views
1

在谷歌瀏覽器上,我們可以通過點擊「下載.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&amp;geo=US-AL%2CUS-AK%2CUS-AZ%2CUS-AR%2CUS-CA&amp;cmpt=geo&amp;content=1&amp;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;">&nbsp;</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; 


      } 
+2

你確定你正在下載完全相同的路徑嗎?它看起來像下載鏈接版本可能傳遞參數告訴它是逗號分隔而不是製表符分隔。 – 2012-01-10 21:29:52

+0

@ScottChamberlain請在結尾處看到我已更新的問題,謝謝 – confusedMind 2012-01-10 21:34:44

+0

請同時包含爲url分配值的代碼 – 2012-01-10 21:37:10

回答

1

你是在你的代碼在斷點處使用export=2export=1在網站代碼。

+0

:)我剛剛發現它,它與出口= 1 ... 非常感謝,仍然好奇鏈接如何從1更改爲2:... – confusedMind 2012-01-10 21:54:50

+0

可能它是從一個選項複選框/放射狀設置其他地方在您手動導航但未通過代碼 – 2012-01-10 21:57:48

+0

設置的頁面/上一頁中設置的頁面/上一頁最有可能,再次感謝:) – confusedMind 2012-01-10 22:03:39