How to login using python?

Hello.
Learning Python and decided to try to log in to the website. No background in web technologies and this process is not know.
When it was just something to take out of the page - used requests.
Tried the simplest way:
url = 'https://...'
login = 'login'
password = 'password'
r = requests.get(url, auth=(login, password))

Anything naturally did not work. Tested on mail.ru me with the famous login and password.
To check used
r.url
Because the address (I think) had to change after login.
Starting address: https://e.mail.ru/login
New address (should be, probably): https://e.mail.ru/messages/inbox/?back=1
Pomimo solve specific example of interest so the same advice "what to read" on this subject, and generally in what side to dig, I want to get at least some idea of how it works. I'm not a programmer and nothing soobo do not know about this, but the python study for yourself.
September 19th 19 at 13:15
4 answers
September 19th 19 at 13:17
Solution
I suspect that you need to use requests.Session()
url = 'https://...'
login = 'login'
password = 'password'
s = requests.Session()
r = s.get(url, auth=(login, password))


Once you come to use some library, start with reading the documentation for that library, usually there are answers to most of your questions.


More often, reading other people's code helps us to understand how (or not so) to use a particular tool. Script authorizeuser in Vkontakte and rocking music, perhaps every aspiring pitonak. It is easy to find.
Some articles on scraping websites with python. They will certainly urllib or requests. For example, here.
In General, seek and ye shall find =)
Here and the result is sent to Google, hmm. =)

upd. Once you smooochies for yourself, try to solve the problem here: checkio.org. Most useful is not just to solve problems, and see how the same task was solved the other lot will open and in the solution of the next tasks will always be available (challenge, if you are an experienced nerd, is also an end in itself). In the examples left by others there as well-documented, and crazy decisions wrapped up in one row.
Thanks for the reply. Now more or less clear where to dig. I can tell why pycharm can't use Session()? AttributeError: 'module' object has no attribute 'Session'
Although in the same pycharm (like terminal) via the interpreter everything works.
Used python 3 - Rodolfo_Thompson10 commented on September 19th 19 at 13:20
: Hard to say. Maybe you run a different version of the file? And where there is AttributeError, you have managed to assign a variable to requests not link to the module, and the reference to something else? Telepathically difficult to understand, magnetic storms probably. But in any case it is not in the version of the language, and most likely not in Pycharm. - Garrett_Lynch commented on September 19th 19 at 13:23
problem solved, it's just I'm stupid) Called the code file too requests.py... - Rodolfo_Thompson10 commented on September 19th 19 at 13:26
September 19th 19 at 13:19
I understand you decided to write a bot to Mail?
Then you read THIS
But useless since you do not understand. BECAUSE before...
IMHO
Well before writing the bots is far from me, it's just for fun. Solve puzzles on pythonchallenge.com there had to use urllib, I decided to find something easier found requests. Then for the sake of interest have decided in addition to open the page more and to authoritiy. (without any purpose) - Rodolfo_Thompson10 commented on September 19th 19 at 13:22
And yet, you apparently forgot to put some link in your answer. - Garrett_Lynch commented on September 19th 19 at 13:25
September 19th 19 at 13:21
Grab!
September 19th 19 at 13:23
I think the fact that mail is AJAX.
Need to do the following through Firebug in Firefox to see what specific requests which the client sends content to the server at login, and play these queries using any convenient tool - grab/requests.
I in this plan like the grab - it quick and easy parses the source code of the page.

Find more questions by tags User identificationPython