2017-07-13 202 views
0
def login_form(login_url, passkey): 
    html = requests.get(login_url) 
    response = requests.post(login_url, data = passkey, cookies = 
    html.cookies) 
    return response 


passkey = { "username": "pass", "password": "password"} 


login_info = login_form('https://www.cpaelites.com/member.php?action=login', 
    passkey) 
print(login_info.url) 

返回URL響應與登錄相同。但它不顯示任何錯誤 我試圖自動化我的登錄過程在cpaelites上,我沒有顯示任何錯誤,但是當我打印響應URL時,它表明我仍然處於當前頁面,這意味着我在Python使用請求登錄網站

+0

請詳細說明你的問題。你在這裏只有幾句話。 – Nabin

+0

你對此有何看法? – Nabin

+0

同時編輯並正確縮進代碼 – Nabin

回答

0

你逝去的憑據在data日誌記錄沒有成功,你可以用auth參數嘗試

from requests.auth import HTTPBasicAuth 
def login_form(login_url, passkey): 
    html = requests.get(login_url) 
    response = requests.post(login_url, auth = HTTPBasicAuth(passkey['username'], passkey['password']), cookies = html.cookies) 
    return response 


passkey = { "username": "pass", "password": "password"} 


login_info = login_form('https://www.cpaelites.com/member.php?action=login', passkey) 
print(login_info.url) 
+0

您可以向我發送OP可能遵循的任何博客,教程或鏈接嗎? – Nabin

+0

@Amey Yadav,仍然是同樣的兄弟,它仍然顯示login_url – ampol