Click here to Skip to main content
15,889,865 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There is a base with several information partly(each part appears after clicking a button). I want a program which loads the html code, takes the needed information,clicks the Next button and moves to the next part while all information is loaded.
C#
HttpWebRequest req; 
HttpWebResponse resp; 
StreamReader sr; 
string content; 
req = (HttpWebRequest)WebRequest.Create("testkrok.org.ua/"); 
resp = (HttpWebResponse)req.GetResponse(); 
sr = new StreamReader(resp.GetResponseStream(), Encoding.GetEncoding("windows-1251"));     
content = sr.ReadToEnd(); 
sr.Close(); 

This is how I gain HTML code, but I do not know how to ckick the button(the button in HTML code does not have name tag) and how get the code of next page. Thanks in advance
Posted
Updated 25-May-13 2:47am
v2
Comments
Prasad Khandekar 25-May-13 8:56am    
Hello,

The button click is actually a POST request, so what you will have to do is to send another web request to the URL to which the form gets submitted upon clicking the button. Simple way to get these url's is to open the site in web browser and manually record these url's. If you want to do this all via code then it's a long route. Besides parsing the HTML dom and figuring out which form the button belongs and the action attribute of the form will tell you the form submission url. This will work provided the button in question is not a submit button, else you may require to parse the javascript or find out the button click handler and then parse that javascript function to figure out the actual url. There can be multiple possibilities and things can really get complicated.

In short access the website in question via a web browser and manually record these url's and parameters used during each GET/POST. You can use chrome developer tools or HttpFox or Fiddler for this purpose. Another way is to use a web testing tool capable of recording the browser interactions. And then use this collected information in your program.

Regards,
[no name] 25-May-13 9:18am    
Sounds like a solution to me...
Sergey Alexandrovich Kryukov 25-May-13 20:29pm    
Agree. Actually, it all depends on what a button does. But, if it ultimately loads something like "next page", the problem is to determine what to do, because it can be a result of some more or less complicated JavaScript, instead of simple and immediate HTTP request...
—SA

1 solution

Hello Soroush Saadatfar,

If this is totally code back, it is much difficult to achieve, if your developing in windows form application,we can achieve by using webbrowser congtrol, by injecting JavaScript to click the next button, and we can collect the data on DocumentComplete Event,

Hope this will works

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900