Login with WebBrowser Control

mixing

Regular Member
Joined
Jan 18, 2014
Messages
412
Reaction score
63
Hey everyone.. I'm messing around with a small xHamster bot and I'm trying to login using the WebBrowser control, but having issues. The login page looks pretty simple and looks like it should login just like any other site unless you get the captcha box. However, that doesn't seam to be the case..

Content from page:
Code:
<div class="item">
                            <div class="top">Login</div>
                            <form id="loginForm" name="loginForm" method="post">
                                <input type="hidden" name="act" value="login">
                                <input type="hidden" name="ref" value="https://xhamster.com/">
                                <input type="hidden" name="stats" class="xsid" value="e43bc5:e721b8d5">
                                                                <table cellpadding="0" cellspacing="4" class="content" width="100%">
                                    <colgroup>
                                        <col width="77">
                                        <col>
                                    </colgroup>
                                    <tbody><tr>
                                        <td>
                                            <label for="username">Username:</label>
                                        </td>
                                        <td>
                                            <input class="inp" name="username" id="username">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <label for="password">Password:</label>
                                        </td>
                                        <td>
                                            <input class="inp" type="password" id="password" name="password">
                                        </td>
                                    </tr>
                                                                            <tr id="loginCaptchaRow" style="display: none;">
                                            <td>
                                                <label>Captcha:</label>
                                            </td>
                                            <td>
                                                <div class="captcha2">        <script language="JavaScript">
            var Captcha = {
                containerId: "loginCaptcha",
                fieldName: "g-recaptcha-response",

                onInit: null,
                onReset: null,
                onSuccess: null,
                onExpire: null,

                _init: function() {
                    grecaptcha.render(Captcha.containerId, {
                        'sitekey' : "6LeRuQYTAAAAAIIJzu4QOt24eoVgxL0Ff8a1g-vA",
                        'callback': Captcha.success,
                        'expired-callback': Captcha.expired
                    });
                    if (Captcha.onInit) {
                        Captcha.onInit();
                    }
                },
                load: function() {
                    if (typeof(grecaptcha) === 'undefined' || typeof(grecaptcha.render) === 'undefined') {
                        $.ajax({'dataType':'script','url': 'https://www.google.com/recaptcha/api.js?hl=en&render=explicit&onload=_captchaInit'});
                    } else {
                        Captcha._init();
                    }
                },
                reset: function() {
                    grecaptcha.reset();
                    if (Captcha.onReset) {
                        Captcha.onReset();
                    }
                },
                getResponse: function() {
                    return grecaptcha.getResponse();
                },
                success: function() {
                    if (Captcha.onSuccess) {
                        Captcha.onSuccess();
                    }
                },
                expired: function() {
                    if (Captcha.onExpire) {
                        Captcha.onExpire();
                    }
                },
                unload: function() {
                    $('#' + Captcha.containerId).empty();
                }
            };
            var _captchaInit = function() {
                Captcha._init();
            };

        </script>
        <div class="g-recaptcha" id="loginCaptcha"></div>
</div>
                                            </td>
                                        </tr>
                                                                    </tbody></table>
                                <table cellpadding="0" cellspacing="0" class="content" width="100%">
                                    <tbody><tr>
                                        <td>
                                            <div class="check">
                                                <input type="checkbox" name="remember" id="loginTime" checked="">
                                                <label for="loginTime">Remember me on this computer</label>
                                            </div>
                                        </td>
                                        <td>
                                            <button type="submit" class="loginBnt">
                                                Login                                                <div class="ajSubmit"></div>
                                            </button>
                                        </td>
                                    </tr>
                                </tbody></table>
                                <div class="bottom">
                                    <a href="https://xhamster.com/password-recovery">
                                        Forgot your password or username?                                    </a>
                                </div>
                            </form>
                        </div>

Codes I've tried..
Code:
wb.Document.GetElementById("username").SetAttribute("value", username)
wb.Document.GetElementById("password").SetAttribute("value", password)
wb.Document.Forms(0).InvokeMember("submit")

The code above inputs the username/password just fine. It even clicks like it should. However, you wind up going back to the homepage and are not logged in...

Code:
wb.Document.GetElementById("username").SetAttribute("value", username)
wb.Document.GetElementById("password").SetAttribute("value", password)

For Each element As HtmlElement In wb.Document.GetElementsByTagName("button")
If element.GetAttribute("type") = "submit" Then
element.InvokeMember("click")
Exit For
End If
Next

The code above does the same as the first I posted. Inputs the fields and clicks. But, only takes you to the homepage not logged in.

Code:
wb.Document.GetElementById("username").SetAttribute("value", username)
 wb.Document.GetElementById("password").SetAttribute("value", password)

For Each element As HtmlElement In wb.Document.GetElementsByTagName("button")
If element.GetAttribute("class") = "loginBnt" Then
element.InvokeMember("click")
Exit For
End If
Next

The code above obviously fills in the fields, but doesn't click anything. From here I can manually click the login button and get taken to the homepage logged in fine...

Any ideas what I can do to get logged in automatically?
 
The best advise I can give is to not use a webbrowser control and use webrequests instead.
 
Code:
wb.Document.GetElementById("username").SetAttribute("value", username)
 wb.Document.GetElementById("password").SetAttribute("value", password)

For Each element As HtmlElement In wb.Document.GetElementsByTagName("button")
If element.GetAttribute("class") = "loginBnt" Then
element.InvokeMember("click")
Exit For
End If
Next

The code above obviously fills in the fields, but doesn't click anything. From here I can manually click the login button and get taken to the homepage logged in fine...

Are you sure that you are finding the button? Maybe add a messagebox / true/false to see if you are finding the button to click.

You would be better off using Selenium or a websocket based approach.
 
Back
Top