Answer the question
In order to leave comments, you need to log in
How to login to ycharts.com using Python?
Can you please tell me how to log in to this site?
I tried several options, the same authorization page is visible at the output in BeautifulSoup:
url = 'https://ycharts.com/login'
login = "login"
password = "password"
session = requests.Session()
auth = HTTPBasicAuth(login, password)
data = {"username":login,"password":password}
r = session.post(url=url, json=data)
s = requests.Session()
r = s.get(url, auth=(login, password))
user_agent_val = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.69 YaBrowser/20.8.0.335 (beta) Yowser/2.5 Safari/537.36'
session = requests.Session()
session.auth = (login, password)
session.get(url, headers = {
'User-Agent': user_agent_val
})
session.headers.update({'Referer':url})
session.headers.update({'User-Agent':user_agent_val})
_xsrf = session.cookies.get('_xsrf', domain="ycharts.com")
session.post(url, {'username': login, 'password': password,
'_xsrf':_xsrf,
'remember':'yes'})
r = session.get(url)
Answer the question
In order to leave comments, you need to log in
I would do this - log in through selenium, copy cookies and use further request'om and BS4. Since a certain "csrfmiddlewaretoken" is transmitted during authorization. I xs how to solve it. It is on the authorization page, but the value does not fit, so it somehow changes or is encrypted with a "salt".
If you log in with a browser and copy the "csrfmiddlewaretoken" parameter and cookies with the name "csrftoken" into the script from it and substituting your data for authorization, you can log in.
import requests
cookies = { 'csrftoken': 'ЦиферкиБуковки'}
headers = { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36',
'Referer': 'https://ycharts.com/login?next=/dashboard/',
}
data = {
'csrfmiddlewaretoken': 'ЦиферкиБуковки',
'username': 'Почта',
'password': 'Пароль'
}
response = requests.post('https://ycharts.com/login', headers=headers, cookies=cookies, data=data)
print(response.text)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question