Answer the question
In order to leave comments, you need to log in
Python Requests How to login to a website?
Good afternoon!
My goal is to
write a program in python. The login and password data are given at the input, the True/False response is given at the output (depending, respectively, on whether the program was able to log in).
Authorization takes place on the Netflix website, this is my task.
Implementation 1:
To begin with, I decided to write code, the result of which was print(r.text). As I understand it, when entering the correct and incorrect login and password, the results ( print(r.text) ) should be different, but they are the same for me. КОД УДАЛЁН
Implementation 2:
Result (with valid/invalid input):
' https://www.netflix.com/Login?nextpage=https%3A%2F... '
Expected result (with valid input):
'https://www.netflix.com/browse ' КОД УДАЛЁН
07/13/19
The 3rd day of my torment has begun, I keep you informed ...
19:55, I returned from school, I continue my futile attempts.
My plans? I'm going to send a post request and then send a get request trying to access https://www.netflix.com/browse (a page that can't be accessed without logging in).
r1 = requests.post(URL_LOG, data=data, headers=headers)
import requests
from lxml import html, etree
URL_LOG = "https://www.netflix.com/login"
URL_MAIN = "https://www.netflix.com/browse"
LOGIN = "MY_LOGIN"
PASSWORD = "MY_PASSWORD"
s = requests.Session()
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
"Connection": "keep-alive",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
}
result = requests.get(URL_LOG, headers=headers)
tree = html.fromstring(result.text)
authURL = list(set(tree.xpath("//input[@name='authURL']/@value")))[0]
print(authURL)
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Content-Length": "313",
"Content-Type": "application/x-www-form-urlencoded",
#"Cookie": "nfvdid=BQFnAAEBEJxbF-N0cMOnfTmUxgT9zsZA_s_RaJ0fg2fV7bXcmlV1-6TTVTaw_1F85KjMtVuQwen50FFpoxN3UajeIhJKq3kGbTUYskxDNoUqSXEKjXzO5Q%3D%3D; memclid=56a08146-0c8d-4804-a0fd-b4f260fa97c7; NetflixId=v%3D2%26ct%3DBQAOAAEBEPWqAdwhDzT9fGigJ17MprOA8HnnmJwbPXxVXQU6l7-AoAf0CdmoJ4OKFuXNmN_Gk1VSxDTfOlR5l6vTdpv2E5uDgM_-TOYTDJUAn6dasLtySfwFb36rx9zlcFZXd2V4ev_Phv7xeXEiIHg2-07r9D_-lk1mOvi0vrkA4Ks0fDdZPUKNzxSv6I9wG1JTy6VgQJWgmHohn0pZllDVFPTgtK7w80Z6zk8HpsS2NhHVN5fFtpDltPxcyhgvpSKoubPjI34tHyi5mdZ4wFWS5Fr-M9mSften3mCFSEbbD60owhL0UqJSTgqj0fEMcvWTHOHyrmMh2mNsnULZLssEAX8nLODtEg..%26bt%3Ddev%26mac%3DAQEAEAABABRtx6338QBfcQqapPEDcdramTVeKrC8MEo.; SecureNetflixId=v%3D2%27mac%3DAQEAEQABABSZexlJGSn3i-7avPfXiwl-aToM9mLR0Js.%26dt%3D1563037431438; flwssn=e448dd2d-4808-4bde-ac20-d2c32f5fc16d; clSharedContext=698074de-40c7-48a6-bf24-2738230a2f51; hasSeenCookieDisclosure=true; didUserInteractWithPage=true; dsca=anonymous; cL=1563038693194%7C156303869337943053%7C156303869386624258%7C%7C4%7Cnull",
"Host": "www.netflix.com",
"Origin": "https://www.netflix.com",
"Referer": "https://www.netflix.com/login",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
}
data = {
"userLoginId": LOGIN,
"password": PASSWORD,
"rememberMe": "true",
"flow": "websiteSignUp",
"mode": "login",
"action": "loginAction",
"withFields": "rememberMe,nextPage,userLoginId,password,countryCode,countryIsoCode",
"authURL": authURL,
"nextPage": "",
"showPassword": "",
#"countryCode": "+49",
#"countryIsoCode": "DE"
}
r1 = s.post(URL_LOG, data=data, headers=headers)
r2 = s.get(URL_MAIN)
print(r1.url)
print(r2.url)
Answer the question
In order to leave comments, you need to log in
THANKS TO ALL! QUESTION CLOSED .
URL_LOG is a constant.
data - a dictionary whose dynamic values are login & password, authURL.
headers - a dictionary whose dynamic value (text variable) is cookies.
All other elements of the dictionaries are static and pulled straight from the site through the developer console.
As far as I know, with any authorization, a certain token is issued, which needs to be written into the session cookie.
Follow the authorization trace in the browser. Look at cookies before and after authorization. I think the answer lies there
R4ndolphC4rter , please write back how you got the necessary cookies and what code you ended up with.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question