Solved

Web Page Login Automation using c#

Posted on 2004-04-06
6
1,513 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
This is an explanation of a simple data model to help parse a JSON feed
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 fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now