登录请求后如何转到下一页 - python

我正在尝试在登录网站后去。我不确定如何做到这一点。从下面的代码中可以看出,我尝试在登录后立即访问下一页,但这会导致重定向到登录页面。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>


慕盖茨4494581
浏览 92回答 1
1回答

米脂

我通过使用解决了它:Sessionsimport&nbsp; requests#loginpayload = {'password': "password"}netGearSiteLogin = requests.post("http://192.168.1.235/login.cgi",data=payload,allow_redirects=True)with requests.Session() as session:&nbsp; &nbsp; post = session.post("http://192.168.1.235/login.cgi", data=payload)&nbsp; &nbsp; r = session.get("http://192.168.1.235/status.cgi")&nbsp; &nbsp; print(r.text)&nbsp; &nbsp;#or whatever else you want to do with the request data!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python