Python登录到Voobly

Python登录到Voobly,python,python-3.x,login,python-requests,Python,Python 3.x,Login,Python Requests,我已经阅读了几十页关于如何使用Python登录网页的内容,但我似乎无法使我的代码正常工作。我正在尝试登录一个名为“Voobly”的网站,我想知道是否有一些特定于Voobly的东西使这变得更加困难。这是我的密码: import requests loginURL = "https://www.voobly.com/login" matchUrl = "https://www.voobly.com/profile/view/124993231/Matches" s = requests.sess

我已经阅读了几十页关于如何使用Python登录网页的内容,但我似乎无法使我的代码正常工作。我正在尝试登录一个名为“Voobly”的网站,我想知道是否有一些特定于Voobly的东西使这变得更加困难。这是我的密码:

import requests

loginURL = "https://www.voobly.com/login"
matchUrl = "https://www.voobly.com/profile/view/124993231/Matches"

s = requests.session()
loginInfo = {"username":"myUsername", "password":"myPassword"}

firstGetRequest = s.get(loginURL) # Get the login page using our session so we save the cookies

postRequest = s.post(loginURL,data=loginInfo) # Post data to the login page, the data being my login information

getRequest = s.get(matchUrl) # Get content from a login - restricted page

response = getRequest.content.decode() # Get the actual html text from restricted page

if "Page Access Failed" in response: # True if I'm blocked
    print("Failed")
else: # If I'm not blocked, I have the result I want
    print("Worked!") # I can't achieve this
如上所述,登录表单将提交到
/login/auth
。但是,cookie是从
/login
URL生成的

使用以下代码:

form = {'username': USERNAME, 'password': PASSWORD}

with requests.Session() as s:
    # Get the cookie
    s.get('https://www.voobly.com/login')
    # Post the login form data
    s.post('https://www.voobly.com/login/auth', data=form)
    # Go to home page
    r = s.get('https://www.voobly.com/welcome')
    # Check if username is in response.text
    print(USERNAME in r.text)
    # True

    r2 = s.get('https://www.voobly.com/profile/view/124993231/Matches')
    if "Page Access Failed" in r2.text:
        print("Failed")
    else:
        print("Worked!")
    # Worked!

注意:登录时根本不需要转到主页部分。它只是用来表示登录成功。

表单已提交到
/login/auth
我已尝试将“/auth”添加到loginURL,但错误仍然存在。因此,您可能需要设置用户代理或引用器或其他标题。对不起,我没有账户,不能再帮你了。它很有效,太棒了!作为我将来的参考,您是如何知道使用/登录cookies的?主要登录表单可在/login页面上找到。/login/auth URL仅用于发布数据;这是从/login页面发布的。这表明cookie是在此页面上生成的。