简体   繁体   中英

How to get url's of Google search results in c#?

I need the get url's of Google search results to a text file, so I used the Google API like this:

GwebSearchClient client = new GwebSearchClient("www.MySite.com"/* Enter the URL of your site here */);
IList<IWebResult> results = client.Search("diet", 32);
foreach (IWebResult result in results)
{
     Console.WriteLine(result.Title);
     Console.WriteLine(result.Url);
}

This gets me the url's , BUT the next thing is that I need it to be the search results of a USA IP address...(and I am not in the USA) I need to set my IP as if I'm in the USA so that the search results will be as if I was doing the search from USA Is there any way to get this done ?

Well a friend from work gave me the simplest solution, and it goes like this:

WebClient webClient = new WebClient();
webClient.Proxy = new WebProxy("proxy string");
string str = webClient.DownloadString("http://www.google.com/search?q=test");
Console.WriteLine(str);

and now just parse the html...

Use a Proxy Server based in the United States for your internet connection. Try: http://www.us-proxy.org/

A suggestion:

1) Create a gmail account with country being usa and try be logged in on search. If you have already logged with an account of a different culture ( say UK and so on) just try to impersonate your account to an usa account of gmail. This should help.

[OR]

2) try proxy as suggested by Daniel. This link can help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM