ScrapySharp does not POST form

1.4k Views Asked by At

I'm using ScrapySharp to post a form to search cases on the Maryland Case Search web app.

Using Fiddler, I found the form name and form fields; however, every time I post, it always come back the initial search page, not the results.

Not sure what I'm missing, see code below.

Any assistance is truly appreciated.

            string url = @"http://casesearch.courts.state.md.us/casesearch/processDisclaimer.jis?disclaimer=Y";

        ScrapingBrowser Browser = new ScrapingBrowser();
        Browser.AllowAutoRedirect = true;
        Browser.AllowMetaRedirect = true;

        WebPage PageResult = Browser.NavigateToPage(new Uri(url));

        PageWebForm form = PageResult.FindForm("inquiryForm");

        form["firstName"] = "";
        form["middleName"] = "";
        form["partyType"] = "";
        form["filingStart"] = "";
        form["filingEnd"] = "";

        form["action"] = "Search";
        form["company"] = "N";
        form["countyName"] = "MONTGOMERY COUNTY";
        form["courtSystem"] = "B";
        form["filingDate"] = "4/4/2016";
        form["lastName"] = "A";
        form["site"] = "CIVIL";

        form.Method = HttpVerb.Post;

        WebPage results = form.Submit();

        Console.WriteLine(results.ToString());
2

There are 2 best solutions below

1
Aleksa Mileusnic On

Try this:

form.FormFields.Where(f => f.Name == "countyName").FirstOrDefault().Value = "MONTGOMERY COUNTY";
0
Albert Zakhia On

You need to make async calls.

Ex:

WebPage mainPage = await browser.NavigateToPageAsync(new Uri(url), HttpVerb.Get,"", "text/html; charset=UTF-8");
PageWebForm form = mainPage.FindFormById("some-form_id");

...

WebPage web = await Task.Run(() => form.Submit()); // submit is not async, so let's force it