Downloading .csv file from Google Trends
<p>I'm looking to download Google Trends data from URLs that I create via code. These URLs, when put into the browser (I use firefox) show a save prompt where I can choose to open or save the file when looking through the browser. However, I am hoping to the the same .csv file containing the Google Trends data via code, and I am stuck. </p>

<p>Here is one of the links that my code creates: [Does prompt to download, however is is Google]</p>

<p><a href="https://www.google.com/trends/trendsReport?hl=en-US&amp;q=debt&amp;geo=US&amp;date=now%207-d&amp;cmpt=q&amp;content=1&amp;export=1" rel="nofollow noreferrer">https://www.google.com/trends/trendsReport?hl=en-US&amp;q=debt&amp;geo=US&amp;date=now%207-d&amp;cmpt=q&amp;content=1&amp;export=1</a></p>

<p>I have two issues with this link, It either downloads a .csv file with Chinese characters (Corrupted I believe?), or downloads some HTML (shown below). When the HTML is saved as an HTML file and run, it takes me to the Google Trends homepage, with the seemingly useless URL of:</p>

<p><a href="https://www.google.com/trends/#geo=US&amp;date=now+7-d&amp;cmpt=q&amp;q=debt&amp;hl=en-US&amp;content=1" rel="nofollow noreferrer">https://www.google.com/trends/#geo=US&amp;date=now+7-d&amp;cmpt=q&amp;q=debt&amp;hl=en-US&amp;content=1</a></p>

<pre><code>&lt;html&gt;&lt;head&gt;&lt;title&gt;Redirecting&lt;/title&gt;

&lt;script type="text/javascript" language="javascript"&gt;
  // 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) {
  }
&lt;/script&gt;

&lt;meta http-equiv="refresh" content="0; url=&amp;#39;http://www.google.com/trends#geo=US&amp;amp;date=now+7-d&amp;amp;cmpt=q&amp;amp;q=debt&amp;amp;hl=en-US&amp;amp;content=1&amp;#39;"&gt;
&lt;/head&gt;
&lt;body bgcolor="#ffffff" text="#000000" link="#0000cc" vlink="#551a8b" alink="#ff0000"&gt;&lt;script type="text/javascript" language="javascript"&gt;
location.replace("http://www.google.com/trends#geo\x3dUS\x26date\x3dnow+7-d\x26cmpt\x3dq\x26q\x3ddebt\x26hl\x3den-US\x26content\x3d1")
&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;
</code></pre>

<p>Also, here is the code that I use to download the .csv file, the basic <code>WebClient</code> download method, the string <code>url</code> can be substituted with the URL from above.</p>

<pre><code>public static void Download(string url)
{
    WebClient webClient = new WebClient();
    webClient.DownloadFile(url, @"C:\Users\Sean\Desktop\StockAp\StockApp\StockApp\report.csv");
}
</code></pre>

<p>Note: I know <code>WebClient</code> downloads the HTML from a page, if there is a way to manipulate the URL to get the data in HTML, that of course would be much easier. However, from what I can tell, somehow getting the CSV would be much better.</p>