How do i get url address from browser(Mozilla/IE) using C#? [duplicate]
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#.
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.
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.
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
精彩评论