从谷歌洞察力下载 csv 进行搜索 [英] download csv from google insight for search
本文介绍了从谷歌洞察力下载 csv 进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要帮助编写脚本使用 c# 从谷歌洞察下载数据
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#
推荐答案
要完成这项工作,您首先需要 验证 以获得可用于访问数据的给定 google 站点的有效 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('
')[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屋!
查看全文