Пример #1
0
        private async Task <bool> Login(Proxy proxy, string username, string password)
        {
            using (WebSession session = new WebSession(proxy)) {
                RequestResponse rr = session.DispatchRequest(new GetRequest("https://www.pornhub.com/login"));

                if (!rr.Validate())
                {
                    Debug.WriteLine("Failed to load login page");
                    return(false);
                }
                Element tokenEl = rr.GetAsDoc().Select("[name=token]").First();

                if (tokenEl is null)
                {
                    Debug.WriteLine("Token not found");
                    return(false);
                }
                string token = tokenEl.Val;

                FormBody fb = new FormBody();
                fb.Add("loginPage", 1);
                fb.Add("redirect", "");
                fb.Add("token", token);
                fb.Add("taste_profile", "");
                fb.Add("username", username);
                fb.Add("password", password);
                fb.Add("remember_me", "on");

                rr = session.DispatchRequest(new PostRequest("https://www.pornhub.com/front/authenticate", fb));

                if (!rr.Validate())
                {
                    if (rr.ResponseCode == 500)
                    {
                        Debug.WriteLine("Blocked connection");
                        return(false);
                    }
                    Debug.WriteLine("Failed to login");
                    return(false);
                }
                Debug.WriteLine(rr.GetResponseContent());
                return(true);
            }
        }