亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

登錄請求后如何轉到下一頁 - python

登錄請求后如何轉到下一頁 - python

慕蓋茨4494581 2022-09-06 18:09:14
我正在嘗試在登錄網站后去。我不確定如何做到這一點。從下面的代碼中可以看出,我嘗試在登錄后立即訪問下一頁,但這會導致重定向到登錄頁面。http://192.168.1.235/status.cgiimport  requests#loginpayload = {'password': "password"}netGearSiteLogin = requests.post("http://192.168.1.235/login.cgi",params=payload)netGearSitePortStatus = requests.get("http://192.168.1.235/status.cgi")print(netGearSitePortStatus.text)結果<head><title>Redirect to Login</title><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><link rel="stylesheet" type="text/css" href="/style.css"><script type="text/javascript" language="JavaScript">function RedirectToLoginPage(){    top.location.href = "/login.cgi";}</script></head><body onload="RedirectToLoginPage();"></body></html>
查看完整描述

1 回答

?
米脂

TA貢獻1836條經驗 獲得超3個贊

我通過使用解決了它:Sessions


import  requests

#login

payload = {'password': "password"}

netGearSiteLogin = requests.post("http://192.168.1.235/login.cgi",data=payload,allow_redirects=True)

with requests.Session() as session:

    post = session.post("http://192.168.1.235/login.cgi", data=payload)

    r = session.get("http://192.168.1.235/status.cgi")

    print(r.text)   #or whatever else you want to do with the request data!


查看完整回答
反對 回復 2022-09-06
  • 1 回答
  • 0 關注
  • 117 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號