我正在尝试使用请求登录网站后向URL发送请求。该URL是初始网站的子级。
Here is the code so far。任何帮助都很棒,谢谢。
刚为您的code sample找到解决方案:您必须设置cookie和auth。
这里的工作代码:
from requests import Session
# Create headers dict.
headers2 = {
# Your headers.
}
Post_Login_URL = 'http://parents.netherhall.org/'
Request_URL = 'https://parents.netherhall.org/parents/students/?admissionno=011161&page=homework'
payload = {
'username': 'your_username',
'password': 'your_password'
}
with Session() as session:
# Send post request to login.
response = session.post(Post_Login_URL, headers=headers, data=payload)
cookies = dict(response.cookies)
# print(post.text) # Page source.
response = session.get(Request_URL, headers=headers, auth=(r'your_username', 'your_password'),
verify=False, cookies=cookies)
print('Logged in successfully:', response.ok)