我正在尝试使用 Python (3.2) 请求登录到站点并在后续页面上导航受保护的内容。但是,当我登录时,它似乎只是让我留在原始登录页面(没有导航到成功页面),并且随后的页面调用仅显示未受保护的内容。你能帮我找出我的代码中的错误吗:
import requests
import sys
class login:
def __init__(self):
self.payload = None
self.c = None
def start(self,username,password,loginpage):
self.payload = {'login':username,'password':password}
self.loginpage = loginpage
def login(self,url):
self.c = requests.session()
response = self.c.post(self.loginpage,data=self.payload)
if response.status_code == 200:
request = self.c.get(url)
print(request.text)
if __name__ == '__main__':
username = 'username'
password = "password"
loginpage = "https://www.clubfreetime.com/login/"
nextpage = "http://www.clubfreetime.com/new-york-city-nyc/free-theater-performances-shows"
login = login()
login.start(username,password,loginpage)
login.login(nextpage)