ScrapySharp没有POST表单

时间:2016-04-05 23:27:32

标签: c# asp.net-web-api web-scraping html-form-post scrapysharp

我正在使用ScrapySharp在Maryland Case Search网络应用上发布表单以搜索案例。

使用Fiddler,我找到了表单名称和表单字段;但是,每次发布时,它总会返回初始搜索页面,而不是结果。

不确定我缺少什么,请参阅下面的代码。

真正感谢任何帮助。

            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 个答案:

答案 0 :(得分:0)

您需要进行异步调用。

例如:

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()); //提交不是异步的,所以我们强制它

答案 1 :(得分:-1)

试试这个:

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