0
我試圖發送一個POST請求到一個站點(https://get.cbord.com/dartmouth/full/login.php)登錄。我想我遇到了我傳入的數據格式的問題,但如實我剛剛開始,所以我不太瞭解這一點。我嘗試使用Chrome開發工具解譯POST請求,這就是我想出的。使用python發送POST請求
#!/usr/bin/env python
import requests
import sys
EMAIL = 'xxx'
PASSWORD = 'xxx'
LOGIN_URL = 'https://get.cbord.com/dartmouth/full/login.php'
FULL_URL = 'https://get.cbord.com/dartmouth/full/funds_home.php'
def main():
# Start a session so we can have persistant cookies
#session = requests.session(config={'verbose': sys.stderr})
session = requests.session()
# This is the form data that the page sends when logging in
login_data = {
'username': EMAIL,
'password': PASSWORD,
'submit': 'Login',
}
# Authenticate
r = session.post(LOGIN_URL, data=login_data)
# Try accessing a page that requires you to be logged in
r = session.get(FULL_URL)
if __name__ == '__main__':
main()
大部分代碼直接複製粘貼從一個類似的問題的答覆。我想我只是不明白如何找出login_data字典應該是什麼。
感謝您的幫助!
帕特
謝謝你,這是非常有幫助 – 2015-01-23 16:16:25