从谷歌搜索下载csv [英] download csv from google insight for search
本文介绍了从谷歌搜索下载csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要帮助编写脚本使用c#从Google洞察中下载数据
Need help writing a script downloads data from google insight using c#
这是下载网址,需要登录
this is the download url and requires a login
http:/ /www.google.com/insights/search/overviewReport?q=test&cmpt=q&content=1&export=2
我如何输入我的用户名和密码?需要一些帮助,新的c#
how do i input my username and password? need some help im new to c#
推荐答案
要使这项工作,您需要先认证,以获得给定的有效 SID
谷歌网站可以用来访问数据。以下是如何实现这一点:
To make this work you need to first authenticate in order to obtain a valid SID
for a given google site which can be used to access data. Here's how you could achieve this:
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);
}
}
}
这篇关于从谷歌搜索下载csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文