C#Httpwebrequest Useragent

时间:2012-11-16 18:53:32

标签: c#

我写了一个脚本来获取Google搜索热门网址。此脚本的一个最大问题是,它将根据我的IP返回搜索结果。也就是说,比如说,我在芝加哥,它将从芝加哥而不是美国的位置返回结果。我认为这可能与useragent有关:

 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/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";

有没有人有关于我为什么要搜索本地的想法?

1 个答案:

答案 0 :(得分:1)

http://support.google.com/websearch/bin/answer.py?hl=en&answer=179386所述,您可以直接在搜索查询中指定一个来覆盖自动位置检测。

  

如果您想查看Google以外某个地区的搜索结果   域名,请在搜索查询中指定位置,如[   自行车修理巴黎]或访问不同的谷歌本地域名   代替。