截至2013年4月30日這個工程。請注意,您使用此方法的速度非常快。
static void Main(string[] args)
{
using (var client = new WebClient())
{
var terms = new List<string>() {"debt", "profit", "euro", "dollar", "financial", "economy", "federal reserve", "earnings", "fed", "consumer spending" , "employment", "unemployment", "jobs" };
var username = "your username";
var password = "password";
var response = client.DownloadString(string.Format("https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email={0}&Passwd={1}&service=trendspro&source=test-test-v1", username, password));
// The SID is the first line in the response
// The Auth line
var auth = response.Split('\n')[2];
client.Headers.Add("Authorization", "GoogleLogin " + auth);
int i = 1;
while (terms.Count > 0)
{
// google limits 5 sets of terms per request
var arr = terms.Take(5).ToArray();
terms = terms.Skip(5).ToList();
var joined = string.Join("%2C%20", arr);
byte[] csv = client.DownloadData(string.Format("http://www.google.com/trends/trendsReport?hl=en-US&q={0}&cmpt=q&content=1&export=1", joined));
// TODO: do something with the downloaded csv file:
Console.WriteLine(Encoding.UTF8.GetString(csv));
File.WriteAllBytes(string.Format("report{0}.csv", i), csv);
i++;
}
}
}
我知道你曾經是能夠做到這一點,但它看起來像它已經過時了。 – 2014-03-16 22:03:55