Link to home
Start Free TrialLog in
Avatar of TCash11
TCash11

asked on

Web Page Login Automation using c#

Hello,
I have a list of the domains that I own and a stats program running on the server that tracks the traffic for each domain (i.e. www.mydomain.com/stats would direct me to the stats page).  I have been writing web data mining crawlersfor a couple months now so I am familiar with HTML parsing, etc..., but I cannot figure out how to automate the login/pass box that my server pops up when navigating to my stats pages.  I have set up my data structures with each of my domains and their appropriate login and pass, now I just have to get them into the text fields and click the button.  Any help is appreciated ahead of time.  THanks,
TCash
Avatar of TCash11
TCash11

ASKER

Point Increase, Thanks Again
TCash
ASKER CERTIFIED SOLUTION
Avatar of Kavar
Kavar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TCash11

ASKER

thanks Kavar, a few tweaks(actually only that networkcredential setup line), and my code worked great.  Much appreciated.
TCash
Avatar of TCash11

ASKER

Out of curiosity, my follow up question is what if there is a login and pas box on the page itself (or any textbox for that matter) as opposed to the popup authentication box; how do you enter text into a textbox on an web page from the c# program?  It may come in handy when creating crawlers in the future.  Thanks
TCash
use the document object model... (document.all("<control Name>").text= )

just wondering what did you change?
Avatar of TCash11

ASKER

----Here is my function; I had everything except the request.Credentials line
private string getHTML(string address)
            {
                  string html = "";
                  System.Net.WebRequest request;
                  System.Net.WebResponse response;
                  try
                  {
                        statusBar1.Text = "Getting HTML for Address: " + address;
                        request = System.Net.WebRequest.Create(address);
                        request.Credentials = new NetworkCredential("login", "pass");
                        response = request.GetResponse();
                        byte [] buffer = new byte[1024];
                  
                        while(response.GetResponseStream().Read(buffer,0,buffer.Length) != 0)
                        {
                              html += System.Text.Encoding.ASCII.GetString(buffer);

                        }
                  }
                  catch
                  {
                        statusBar1.Text = "exception getting html";
                        MessageBox.Show("Error Getting HTML");
                  }
                  return html;
            }

-------Haven't played with the document object yet , but thanks for the response.  
-TCash