navigating site programmatically
I am currently working on a project for which i have to navigate site programmatically. I am using C#. In some case sites navigates(change contents of page) on the event of a control, while URL remain same. like the one below
http://www.centurysecuritiesng.com/Home/tabid/36/ctl/listing/mid/410/Default.aspx
On this page there is a dropdown(Price List as at) and the content of the page changes on dropdown item change, while URL of the page remain same. can anybody suggest that how can i achieve this programmatically, mean changing dropdown item dynamically and getting its content against that dropdown item.
In short i want dynamic content of the page which 开发者_运维问答is coming against event of a control, based on some value. Which in my case is onchange event of dropdrown based on selected value of the dropdown
Thanks in advance.
You can try with Selenium. Take a look at: http://seleniumhq.org/. Also, you can write web crawler in many languages of your choice. If you prefer .NET, take a look at HttpWebRequestClass.
It's not clear from your question, but I assume you're trying to make your C# app automate a Web browser that's running as a separate application (as opposed to embedding a WebBrowser control in your app and automating that).
This sounds like the sort of thing WatiN is meant to automate. It's intended for automated tests (which may or may not be what you're doing) but gives you an easy way to drive an external instance of either IE or FireFox, navigate to pages, find text fields and type into them, click buttons, etc.
A sample code snippet from their site:
using (var browser = new IE("http://www.google.com"))
{
browser.TextField(Find.ByName("q")).TypeText("WatiN");
browser.Button(Find.ByName("btnG")).Click();
Assert.IsTrue(browser.ContainsText("WatiN"));
}
I think you are trying to do page scraping. If yes then HTML Agility Pack is best choice for you to use in your .NET application and scrap the page programmatically.
精彩评论