Solved

Web Page Login Automation using c#

Posted on 2004-04-06
6
1,517 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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 …

808 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