Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to scrape a web page. Using C# and WinForms. I can load the page into a WebBrowser, invoke the post method for a form, and get the results. I'd like to then change the date and resubmit the form. Unfortunately the control for picking the date is a read only control driven by a lot of ajax code (axd files) that aren't easily accessible.

I thought it would be better to try to intercept the POST data before it goes to the server and change the date string.

I can't seem to find a way to get the post data before it is sent to the server. Is there some way to grab it, modify it, and then send it on it's way?

What I have tried:

public void CompletedHander(object sender,
      WebBrowserDocumentCompletedEventArgs e)
{
      WebBrowser wb = ((WebBrowser)sender);

      HtmlElement button = wb.Document.GetElementById("ctl00$WebSplitter1$tmpl1$ContentPlaceHolder1$HeaderBTN1$btnRetrieve");
      if (button != null)
      {
           _pushed = true;
           button.InvokeMember("click");
      }
}
Posted
Updated 24-May-17 6:46am

1 solution

Turned out there was a control I could use java to invoke which created the correct viewstate and post data.

public void CompletedHander(object sender,
      WebBrowserDocumentCompletedEventArgs e)
{
    HtmlElement webDatePicker = wb.Document.GetElementById("ctl00_WebSplitter1_tmpl1_ContentPlaceHolder1_dtePickerBegin");

    string szJava = string.Empty;
    szJava = "a = $find(\"ctl00_WebSplitter1_tmpl1_ContentPlaceHolder1_dtePickerBegin\"); a.set_text(\"5/20/2017\");";
    object a = wb.Document.InvokeScript("eval", new object[] { szJava });
    if (webDatePicker != null)
        webDatePicker.InvokeMember("submit");

    HtmlElement button = wb.Document.GetElementById("ctl00$WebSplitter1$tmpl1$ContentPlaceHolder1$HeaderBTN1$btnRetrieve");
    if (button != null)
    {
         button.InvokeMember("click");
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900