3

I Want to Enter to another site with my program(asp.net/C#).

  1. HOW can i crawl the site and find username & password text boxes and fill them with needed data.
  2. then HOW can i press/Fire the login button?

NOTE : I crawl the site with HtmlAgilityPack before..is there any way to use this dll or any other dlls?

for example username is : user password is : passcode and the login button id is : Press how can i do this?

Nathan White
  • 1,082
  • 7
  • 21
Amin AmiriDarban
  • 2,031
  • 4
  • 24
  • 32
  • 3
    You would simply send a post request specifically crafted for their login page. That is all that a "button click" usually is. – Stefan H Jan 23 '13 at 19:45
  • i can not underestand...can you please show me example code? – Amin AmiriDarban Jan 23 '13 at 19:53
  • Example: http://stackoverflow.com/questions/4015324/http-request-with-post – Stephen Gilboy Jan 23 '13 at 19:53
  • 1
    Going into web crawling and trying to drive pages through code will require you to understand what happens in the HTTP protocol. When you first navigate to a page, that is a GET request. When you click a button (or potentially other activities) your browser performs a POST to the page and sends a set of parameters (look at the network tab under the developer tools in chrome with F12 to see what gets sent when you hit submit on a page form). – Stefan H Jan 23 '13 at 19:55

1 Answers1

4

You don't want to work that way. You need to simulate what the site would do once that form was submitted with a Post request to the server, passing the values. You can evaluate what the site does by using Fiddler2 and performing the form submission normall,y then sumulate as below:

HttpWebRequest request;
        HttpWebResponse response;
        var responseData = "";
        var strUrl = "https://auctions.godaddy.com/trpSearchResults.aspx";

        var postData = string.Format("action=review_selected_add&items={0}_B_{1}_1|&rnd={2}&JlPYXTX=347bde7", auctionRef, bid,
            randomDouble(0, 1).ToString("0.00000000000000000"));
        request = (HttpWebRequest)WebRequest.Create(strUrl);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = postData.Length;
        request.Accept = "text/html, application/xhtml+xml, */*";
        request.Accept = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/x-silverlight, application/x-silverlight-2-b2, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*";
        request.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11";
        request.Headers.Add("Accept-Encoding", "deflate");
        request.Referer = "auctions.godaddy.com";
        request.Headers["my-header"] = "the-value";
        request.KeepAlive = true;
        request.CookieContainer = cookies;
        request.Timeout = Timeout.Infinite;

        var stOut = new StreamWriter(request.GetRequestStream());
        stOut.Write(postData);
        stOut.Flush();
        stOut.Close();
        stOut = null;

        response = (HttpWebResponse)request.GetResponse();
        response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
        var encoding = new System.Text.UTF8Encoding();
        var responseReader = new StreamReader(response.GetResponseStream(), encoding, true);

        encoding = new System.Text.UTF8Encoding();
        responseReader = new StreamReader(response.GetResponseStream(), encoding, true);

        responseData = responseReader.ReadToEnd();
        response.Close();
        responseReader.Close();

Just Make a class using the above for posting data and return the html.

Aaron Gibson
  • 1,280
  • 1
  • 21
  • 36