重定向后如何加载HTMLDocument

时间:2019-01-12 17:34:52

标签: c#

我想问一下,当我单击登录表单的提交按钮时,它会将我重定向到另一个站点,所以我的问题是如何从该站点加载HTMLDocument。

谢谢。

编辑:

    webBrowser1.Navigate("example.com");
    while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
    {
        Application.DoEvents();
    }

    HtmlDocument document = webBrowser1.Document;
    HtmlElement username = document.GetElementById("bgcdw_login_form_username");
    HtmlElement password = document.GetElementById("bgcdw_login_form_password");

    OpenFileDialog open = new OpenFileDialog();
    open.ShowDialog();
    StreamReader soubor = new StreamReader(open.FileName);

    if(new FileInfo(open.FileName).Length != 0)
    {
        username.SetAttribute("value", soubor.ReadLine());
        password.SetAttribute("value", soubor.ReadLine());
    }

    var elements = webBrowser1.Document.GetElementsByTagName("input");
    foreach (HtmlElement element in elements)
    {
        if (element.GetAttribute("type") == "submit")
        {
            element.InvokeMember("click");
        }
    }

0 个答案:

没有答案