2017-09-08 9 views
0

リクエストを使用してウェブサイトにログインしようとしました。私はログインページのコード上のいくつかの入力を見てきましたが、私はリクエストの投稿で何を入力すべきですか?私は以下のコードを書いたが、それはあなたがそれを確認することはできません。Python Requests投稿

以下は、ウェブサイトとスクリプトのログインフォームの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
payload = {"session_key": "......", "session_password": "....", "isJsEnabled": "false", "loginCsrfParam": "authenticity_token"} 

、あなたは文字列として "authencity_token" を投稿するには、変数の値をしたいので、それらの引用符を削除します。あなたのノートの

payload = {"session_key": "......", "session_password": "....", "isJsEnabled": "false", "loginCsrfParam": authenticity_token} 
+0

感謝を。私は試してみましたが、動作しません。送信ボタンやisJsEnabledなどの他の入力はどうでしょうか?私たちもそれらを投稿する必要がありますか? –

+0

もちろん、可能な限り投稿する必要があります。可能な限り「通常の」使用を模倣する。 また、リクエストヘッダーをチェックし、投稿することもできます... –

関連する問題