gpt4 book ai didi

Python 登录 Voobly

转载 作者:太空宇宙 更新时间:2023-11-03 10:22:32 25 4
gpt4 key购买 nike

我已经阅读了数十页有关如何使用 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

最佳答案

如上所述in the comments ,登录表单提交到/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!

注意:登录根本不需要转到主页部分。仅用于表明登录成功。

关于Python 登录 Voobly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49623406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com