1
要求ライブラリを使用してWebサイトにログインするためのpythonスクリプトを作成しようとしています。 これはログインフォームです。Pythonリクエストを使用してウェブサイトにログインすると400を返す
<form action="/login" method="POST"><input type="hidden" name="post_key" value="b762c617d52cf987fdb40d74c6a04e07"><input type="hidden" name="return_to" value="http://www.pixiv.net/"><input type="hidden" name="lang" value="en"><input type="hidden" name="source" value="pc"><div class="input-field-group"><div class="input-field"><input type="text" name="pixiv_id" placeholder="E-mail address/pixiv ID" autocapitalize="off"></div><div class="input-field"><input type="password" name="password" placeholder="Password" autocapitalize="off">
これは私のコードです。
import requests
url = "https://accounts.pixiv.net/login"
# set requests headers
headers = {
'Connection':'keep-alive',
'User-agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36',
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'
}
# get user id and password
pixiv_id = raw_input("Your pixiv id : ")
password = raw_input("Your pixiv password: ")
payload = {
'action' : '/login',
'return_to' : 'http://www.pixiv.net'
}
payload['pixiv_id']=pixiv_id
payload['password']=password
with requests.Session() as s:
r = s.post(url, data=payload, headers=headers)
response = s.get("http://www.pixiv.net")
print r.status_code
print response.text
私の質問は、フォームのすべての隠し値を入力する必要がありますか? また、私は何度も実行していますが、常に400を返します。誰かが私のコードの問題を理解するのを助けることができますか?