Solved

Web Page Login Automation using c#

Posted on 2004-04-06
6
1,516 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:TCash11
  • 4
  • 2
6 Comments
 

Author Comment

by:TCash11
ID: 10768004
Point Increase, Thanks Again
TCash
0
 
LVL 10

Accepted Solution

by:
Kavar earned 500 total points
ID: 10771822
string pc;
System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = new NetworkCredential(Uname, UPass);
pc  = Encoding.ASCII.GetString(wc.DownloadData(<your web url here>));
0
 

Author Comment

by:TCash11
ID: 10778615
thanks Kavar, a few tweaks(actually only that networkcredential setup line), and my code worked great.  Much appreciated.
TCash
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:TCash11
ID: 10779554
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
0
 
LVL 10

Expert Comment

by:Kavar
ID: 10781026
use the document object model... (document.all("<control Name>").text= )

just wondering what did you change?
0
 

Author Comment

by:TCash11
ID: 10784632
----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
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question