需要帮助编写脚本使用c#从google insight下载数据
这是下载网址,需要登录
http://www.google.com/insights/search/overviewReport?q=test&cmpt=q&content=1&export=2
我如何输入用户名和密码?需要一些新的帮助c#
为了完成这项工作,您需要首先进行身份验证,以获得SID可用于访问数据的给定Google网站的有效身份.以下是您如何实现这一目标:
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)