如何在登录请求后转到下一页-python
我正在尝试转到如何在登录请求后转到下一页-python,python,http,python-requests,Python,Http,Python Requests,我正在尝试转到http://192.168.1.235/status.cgi登录网站后。我不知道该怎么做。从下面的代码中可以看出,我尝试在登录后立即访问下一个页面,但是这会导致重定向到登录页面 import requests #login payload = {'password': "password"} netGearSiteLogin = requests.post("http://192.168.1.235/login.cgi",params=payload) netGearSiteP
http://192.168.1.235/status.cgi
登录网站后。我不知道该怎么做。从下面的代码中可以看出,我尝试在登录后立即访问下一个页面,但是这会导致重定向到登录页面
import requests
#login
payload = {'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>
重定向到登录
函数RedirectToLoginPage()
{
top.location.href=“/login.cgi”;
}
我通过使用会话解决了这个问题
:
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!