1

我用 C# 编写了一个在 Google 搜索中返回搜索结果的工具。但是,即使我关闭了 cookie 并删除了浏览器历史记录。它仍然返回我当地的搜索结果:芝加哥。我使用的网址是:

URL = "https://www.google.com/search?q=health and beauty&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&start=0&num=9&gl=us "

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Accept = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
request.Headers["Accept-Language"] = "en-US";
//request.UserAgent = "Mozilla/6.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/16.0.2";
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";    
request.KeepAlive = true;
request.AllowAutoRedirect =true;
request.Timeout = 60000;
request.Method = "GET";


HttpWebResponse response = (HttpWebResponse)request.GetResponse();

if (response.StatusCode == HttpStatusCode.OK)
{
    Stream responseStream = response.GetResponseStream();
    StreamReader myStreamReader = new StreamReader(responseStream);
    responseData = myStreamReader.ReadToEnd();
}
response.Close();

在该工具中,它不断为我提供芝加哥的结果。有没有办法让我得到美国而不是芝加哥的结果?

4

1 回答 1

0

不要点击 google.com,而是点击 google.ca,但继续传入 gl=us 参数。所以你的 URL 看起来像:

https://www.google.ca/search?q=health and beauty&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&start=0&num=9&gl=us

这似乎绕过了我测试过的搜索词的地理定位。

于 2012-11-30T19:37:40.307 回答