1

Possible Duplicate:
Get Firefox URL?

I am writing a program to search for a keyword in google and get the links displayed in search back to the program. Can anyone please suggest how can i get url from browser in C#.

Community
  • 1
  • 1
  • Are you looking for a regex to search the page HTML for urls? Can you please clarify what you are trying to do? – Paul Mar 08 '11 at 22:50

3 Answers3

0

I highly suggest that you take a look at WatiN it's like using jQuery for javascript, except it's for c#. You can instruct your program to open up a new browser window, navigate to google.com, search, and then parse the links.

Of course this can be done without WatiN, but you would be writing more code.

The Muffin Man
  • 19,585
  • 30
  • 119
  • 191
0

Maybe you would find it easier to use a Google API to do searches:

http://code.google.com/apis/customsearch/v1/overview.html

This way there's no need to parse the HTML results to get the URL and title of each site in the search results.
Anyway, if you really want to do a "normal" search and parse the results yourself, a good library is the HTML Agility Pack. See How to use HTML Agility pack.

Community
  • 1
  • 1
tiago2014
  • 3,392
  • 1
  • 21
  • 28
-1

Sample url: www.sample.com/page.aspx?foo=bar

var urlAbsolute = HttpContext.Request.Url; //returns www.sample.com/page.aspx?foo=bar
var urlRelative = HttpContext.Request.RawUrl; //returns page.aspx?foo=bar
Paul
  • 12,392
  • 4
  • 48
  • 58