从谷歌洞察下载csv进行搜索
需要帮助编写脚本使用c#从google insight下载数据
这是下载url,需要登录
http://www.google.com/insights/search/overviewReport?q=test&cmpt=q&content=1&export=2
我如何输入用户名和密码? 需要一些新的帮助c#
要完成此工作,您需要先进行身份validation ,以获取可用于访问数据的给定Google网站的有效SID
。 以下是您如何实现这一目标:
class Program { static void Main(string[] args) { using (var client = new WebClient()) { // TODO: put your real email and password in the request string var response = client.DownloadString("https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email=youraccount@gmail.com&Passwd=secret&service=trendspro&source=test-test-v1"); // The SID is the first line in the response var sid = response.Split('\n')[0]; client.Headers.Add("Cookie", sid); byte[] csv = client.DownloadData("http://www.google.com/insights/search/overviewReport?q=test&cmpt=q&content=1&export=2"); // TODO: do something with the downloaded csv file: Console.WriteLine(Encoding.UTF8.GetString(csv)); File.WriteAllBytes("report.csv", csv); } } }
好吧,几天后就改变了。
现在你必须传递auth而不是SID。
现在代码是:
class Program { static void Main(string[] args) { using (var client = new WebClient()) { // TODO: put your real email and password in the request string var response = client.DownloadString("https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email=youraccount@gmail.com&Passwd=secret&service=trendspro&source=test-test-v1"); // The Auth line var auth = response.Split('\n')[2]; client.Headers.Add("Authorization", "GoogleLogin " + auth); byte[] csv = client.DownloadData("http://www.google.com/insights/search/overviewReport?q=test&cmpt=q&content=1&export=2"); // TODO: do something with the downloaded csv file: Console.WriteLine(Encoding.UTF8.GetString(csv)); File.WriteAllBytes("report.csv", csv); } } }
现在它再次为我工作。