Python 3.5.1 urllib.request

03/08/2016 00:52 lorddragon002#1
Hi,

i started experiment with python, and i stuck on sending POST request to website.
Is there anyone, who can help me?

I have this form on website, and i need to send "user" and "password".
I tried few ways, but i´m more confused than smart.

HTML Code:
<form action="index.php?action=login&show_server_selection=1" method="post" id="login_form" onsubmit="return Index.login_submit();">
		<div>
			<label for="user">
				<strong >User name:</strong>
				<span >
					<input id="user" name="user" class="text" type="text" value=""
						   onkeydown="if((e=window.event||event) && e.keyCode == 13 && $('#user').val() && $('#password').val()) $('#login_form').submit()"/>
				</span>
			</label>
			<label for="password">
				<strong >Password:</strong>
				<span >
					<input name="clear" type="hidden" value="true" />
					<input id="password" name="password" class="text" type="password"
						   onkeydown="if((e=window.event||event) && e.keyCode == 13 && $('#user').val() && $('#password').val()) $('#login_form').submit()"/>
				</span>
			</label>
			
			<input type="submit" id="login_submit_button" style="display: none" />

			<label for="cookie" class="remember_me">
				<input id="cookie" type="checkbox" name="cookie" value="true" checked="checked" />
					Remember me
			</label>

			<div id="login-buttons">
						
							
				<div id="js_login_button">
					<a href="#" onclick="$('#login_submit_button').click()" class="login_button">
						<span class="button_left"></span>
						<span class="button_middle">Login</span>
						<span class="button_right"></span>
					</a>
				</div>			
			</div>

			<br style="clear:both;"/>
		</div>
	</form>
Have a nice day guys.

Best regards,
lorddragon
03/08/2016 13:20 MrDami123#2
First check your whole post request with a browser.
Press F12 go to 'Network' and check which info your browser sends to the server. Replicate it in your script.
03/08/2016 18:03 lorddragon002#3
Heh, finally i can move on.
Well, it works.
Thanks.


Now i have to set up cookies.

There is tons of tutorial with librery "httplib2", but it´s not working on version 3.5.1
Do u have some ideas?
03/08/2016 18:18 MrDami123#4
Always use [Only registered and activated users can see links. Click Here To Register...].

edit:
Use 'requests.Session()' to auto-save cookies within the session.