我正在使用请求库登录到包含以下表单的页面:
<form action="login.php" method="post" id="login">
<input type="hidden" name="__CSRFToken__" value="022d7665c7dc20683af1a66680560500f9ad4770" /> <input type="hidden" name="do" value="scplogin">
<fieldset>
<input type="text" name="userid" id="name" value="" placeholder="E-mail ou Usuário"
autofocus autocorrect="off" autocapitalize="off">
<input type="password" name="passwd" id="pass" placeholder="Senha" autocorrect="off" autocapitalize="off">
<button class="submit button pull-right" type="submit" name="submit"><i class="icon-signin"></i>Login</button>
</fieldset>
</form>
我使用了以下代码,但没有成功
Import requests
from bs4 import BeautifulSoup
session = requests.Session()
url = "https://page.with.form/scp/login.php"
# Retrieve the CSRF token first
soup = BeautifulSoup(client.get(url).content)
csrftoken = soup.find('input', dict(name='__CSRFToken__'))['value']
print(csrftoken)
params = {'__CSRFToken__': csrftoken, 'do': 'scplogin', 'passwd':'password', 'submit':'', 'userid':'username'}
s = session.post(url,params)
print("Cookie is set to:")
print(s.cookies.get_dict())
print("----------------")
print(s.text)
有人能帮我吗?谢谢