Home python Log in to Yandex by using Python

Log in to Yandex by using Python

Author

Date

Category

We need to get some data from Yandex account with a script (selenium and api will not work). I tried to sign in using the query, the result – the login page without any data. How can I solve this problem?

from requests import post
from fake_useragent import UserAgent
link = "https://passport.yandex.com/auth"
user = UserAgent (). random
header = {
  'User-agent': user
}
data = {
  'Login': 'login',
  'Password': 'password',
}
response = post (link, data = data, headers = header) .text
print (response)

Last modified:

I noticed that authorization, after entering the login redirection is. Changed code. Now everything should be preserved (a cookie while redirecting) is sending the right data to each of the pages, just learned how to generate process_uuid. But still it does not work. There are so general “can not post”.

from requests import post, Session
from fake_useragent import UserAgent
from uuid import uuid4
link = "https://passport.yandex.ru/auth"
link2 = "https://passport.yandex.ru/auth/welcome"
user = UserAgent (). random
session = Session ()
header = {
  'User-agent': user
}
data = {
  'Login': 'login',
  'Process_uuid': uuid4 (),
}
data2 = {
  'Password': 'password',
  'Retpath': 'https://passport.yandex.ru/profile'
}
response = session.post (link, data = data, headers = header) .text
response = session.post (link2, data = data2, headers = header) .text
with open ( "auth.html", "w") as file:
  file.write (response)

What is the problem?


Answer 1, Authority 100%

The problem was in the wrong sending data. Even csrf token and uuid are not needed.

from requests import post, Session
from fake_useragent import UserAgent
link = "https://passport.yandex.com/auth"
user = UserAgent (). random
Headers = {
'User-agent': user
}
data = {
'Login': 'login',
'Passwd': 'password',
}
session = Session ()
responce = session.post (link, headers = headers, data = data)
with open ( "responce.html", "w") as file:
  file.write (responce.text)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions