authentication - Login into web site using Python -
this question has been addresses in various shapes , flavors have not been able apply of solutions read online.
i use python log site: https://app.ninchanese.com/login , reach page: https://app.ninchanese.com/leaderboard/global/1
i have tried various stuff without success... using post method:
import urllib import requests ourl = 'https://app.ninchanese.com/login' ocredentials = dict(email='myemail@hotmail.com', password='mypassword') osession = requests.session() oresponse = osession.post(ourl, data=ocredentials) oresponse2 = osession.get('https://app.ninchanese.com/leaderboard/global/1')
using authentication function requests package
import requests osession = requests.session() oresponse = osession.get('https://app.ninchanese.com/login', auth=('myemail@hotmail.com', 'mypassword')) oresponse2 = osession.get('https://app.ninchanese.com/leaderboard/global/1')
whenever print oresponse2, can see i'm on login page guessing authentication did not work.
could please advise how achieve this?
you have send csrf_token
along login request:
import urllib import requests import bs4 url = 'https://app.ninchanese.com/login' credentials = dict(email='myemail@hotmail.com', password='mypassword') session = requests.session() response = session.get(url) html = bs4.beautifulsoup(response.text) credentials['csrf_token'] = html.find('input', {'name':'csrf_token'})['value'] response = session.post(url, data=credentials) response2 = session.get('https://app.ninchanese.com/leaderboard/global/1')
Comments
Post a Comment