Reputation: 2653
At google insight we can search a keyword and download the result by clicking the "Download .csv" file button. I coded the process to run on multiple keywords.
When I download the .csv
file from google insight and open it in notepad I get this format.
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
However when I download it from code using:
byte[] csv = client.DownloadData(url);
File.WriteAllBytes(path, csv);
I get this format:
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
But my requirement is to get the code in the first format as it is to be uploaded somewhere where the first format is needed. What is wrong with my code and why is the format changing?
I am using this url behind the button:
<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>
Code that assign the value to url:
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;
}
Upvotes: 1
Views: 560
Reputation: 127563
You are using export=2
in your code at the breakpoint but it is export=1
in the website code.
Upvotes: 1