我尝试使用请求登录网站。我在登录页面的代码上看到了几个输入,我应该在请求帖子中输入什么输入。我已经编写了下面的代码,但它无法检查它。
以下是网站登录表单和我的脚本的HTML代码。你能检查一下吗?
#login form HTML Code
<input autocapitalize="off" autofocus="autofocus" class="login-email" id="login-email" name="session_key" placeholder="Email" tabindex="1" type="text"/>
<input aria-required="true" class="login-password" id="login-password" name="session_password" placeholder="Password" tabindex="1" type="password">
<input class="login submit-button" id="login-submit" tabindex="1" type="submit" value="Sign in"/>
<input name="isJsEnabled" type="hidden" value="false">
<input id="loginCsrfParam-login" name="loginCsrfParam" type="hidden" value="73b525bd-1656-4ee0-879f-b4c1d7959656"/>
#This is the code
import requests
from bs4 import BeautifulSoup
c = requests.Session()
login_url = "#some url"
results = c.get(login_url)
soup = BeautifulSoup(results.content, 'html.parser')
key = soup.find(id="loginCsrfParam-login")
authenticity_token = key[u'value']
print(authenticity_token)
payload = {"session_key": "......", "session_password": "....", "isJsEnabled": "false", "loginCsrfParam": "authenticity_token"}
c.post("#some url", data = payload)
r = c.get("#some url")
soup2 = BeautifulSoup(r.content, 'html.parser')
print(soup2.text)
答案 0 :(得分:0)
payload = {"session_key": "......", "session_password": "....", "isJsEnabled": "false", "loginCsrfParam": "authenticity_token"}
那里,你发布&#34; authencity_token&#34;作为字符串,您需要变量值,因此请删除这些引号:
payload = {"session_key": "......", "session_password": "....", "isJsEnabled": "false", "loginCsrfParam": authenticity_token}