簡體   English   中英

為什么我的 Python POST 請求會引導我進入初始網頁?

[英]Why does my Python POST request lead me to the initial webpage?

我是這個論壇的新手,對編碼也比較陌生

這個問題已經在這里問過了,但解決方案似乎對我不起作用。

我想使用 Python 發布請求登錄 index.php 頁面,但響應 url 仍然與初始登錄頁面相同,表明登錄不成功。

import requests as r

login_url = "https://www.example.com/index.php?login"
index_url = "https://www.example.com/gymla/index.php" #The url I want to be directed to

data = {
    "isiwebuserid": "username",
    "isiwebpasswd": "password",
    "submit": "Senden"
}

s = r.session()
response = s.post(login_url, data=data)

print(response.url)
if response.url == login_url:
    print("The attempt did not work.")

如果登錄 URL 可能是錯誤的,我已經檢查了 <form action,但它似乎沒問題。 表格資料也齊全。 還有什么可能是錯的?

Url 不改變但保持固定,試試這個

if response.status_code != 200:
    print("The attempt did not work.")

謝謝你們回答我的問題。 解決方案確實是使用"Submit"而不是"Senden"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM