[問題] 該怎麼用python登入自己寫的表單?

看板Python作者 (php er)時間9年前發表 (2016/04/12 15:55), 9年前編輯推噓0(004)
留言4則, 1人參與, 最新討論串1/2 (看更多)
大家好 新手在下 寫了一個測試網頁 位在 http://pure.comxa.com/index.html 帳號是 test@test.com 密碼是 test 登入成功 會顯示 you did it 登入失敗 會跳js窗 說error 現在 想用python 3 練習登入 然而 每次都會傳回登入錯誤的頁面 不知道錯在哪 實在是很困惑 不知是否有高手能救救我呢???? >< 謝謝各位 程式碼如下 import requests import urllib from requests import session headers = {'User-Agent': 'Mozilla/5.0'} payload = { 'action': 'loginSuccessDisplay.php', 'userName':'test@test.com', 'pswd':'test' } with session() as c: c.post('http://pure.comxa.com/index.html',headers=headers,data=payload) response = c.get('http://pure.comxa.com/loginSuccessDisplay.php') # 改成index.html還是不行 會返回登入頁面@@ print(response.headers) print(response.text) 話說我的網頁後台並不會產生session 而是只是單純的驗證username pswd有沒有match 請問這是問題癥結點嗎? 還是我的 request 寫錯了呢? >< 懇請大大賜教謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.217.5.163 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1460476500.A.2CF.html ※ 編輯: phpjson (180.217.5.163), 04/13/2016 01:17:22

04/13 01:22, , 1F
oh! 我知道了 我把with session() as c給刪了
04/13 01:22, 1F

04/13 01:23, , 2F
然後就好了 是因為後台沒有session的關係???
04/13 01:23, 2F

04/13 01:27, , 3F
但是也有點好奇, 自動跳轉的網頁 get back 的url 該填啥
04/13 01:27, 3F

04/13 01:28, , 4F
請問有前輩大大能解惑嗎??? 感恩....
04/13 01:28, 4F
文章代碼(AID): #1N3HfKBF (Python)
文章代碼(AID): #1N3HfKBF (Python)