我正在尝试在登录网站后去。我不确定如何做到这一点。从下面的代码中可以看出,我尝试在登录后立即访问下一页,但这会导致重定向到登录页面。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!
添加回答
举报
0/150
提交
取消