WebBrowser无法创建帐户

问题描述

我写了一些代码,使我可以使用C#在网站上自动创建一个帐户。不幸的是,由于我没有从网站收到确认电子邮件,因此代码似乎未按预期工作。

这是我的代码(我只复制了重要部分以使其尽可能客观)

webBrowser.Navigate("https://account.protonvpn.com/signup");
webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
MessageBox.Show("end");

private void webBrowser_DocumentCompleted(object sender,WebBrowserDocumentCompletedEventArgs e)
{
    if (webBrowser.ReadyState != WebBrowserReadyState.Complete)
        return;

    if (webBrowser.Url.ToString() == "https://account.protonvpn.com/signup")
    {
        buttons = webBrowser.Document.GetElementsByTagName("button");
        foreach (HtmlElement button in buttons)
        {
            if (button.InnerText == "Get Free")
            {
                button.InvokeMember("click");
                MessageBox.Show("clicked");
            }
            else
            {
                MessageBox.Show("not clicked");
            }
        }
        return;
    }
    if (webBrowser.Url.ToString() == "https://account.protonvpn.com/signup/account")
    {
        webBrowser.Document.GetElementById("username").SetAttribute("value","username");
        webBrowser.Document.GetElementById("password").SetAttribute("value","password");
        webBrowser.Document.GetElementById("passwordConfirmation").SetAttribute("value","password");
        webBrowser.Document.GetElementById("email").SetAttribute("value","email");
        buttons = webBrowser.Document.GetElementsByTagName("button");
        foreach (HtmlElement button in buttons)
        {
            if (button.InnerText == "Create account")
            {
                button.InvokeMember("click");
                MessageBox.Show("account created");
            }
            else
            {
                MessageBox.Show("error");
            }
        }
        return;
    }

    if (webBrowser.Url.ToString() == "https://account.protonvpn.com/signup/verification")
    {
        buttons = webBrowser.Document.GetElementsByTagName("button");
        foreach (HtmlElement button in buttons)
        {
            if (button.InnerText == "Send")
            {
                button.InvokeMember("click");
                MessageBox.Show("account created!");
            }
            else
            {
                MessageBox.Show("error!");
            }
        }
        return;
    }
}

在运行代码时,我还会遇到一些“脚本错误”,不确定如何解决它们,也不确定运行代码时是否会影响到任何东西。

Screenshots of script errors

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...