Python mechanizes site login

I am trying to enter a website using Python and Mechanize, however I am having problems trying to make the POST data behave the way I want.

Essentially, I want to replicate this using mechanize and Python:

wget --quiet --save-cookies cookiejar --keep-session-cookies --post-data "action=login&login_nick=USERNAME&login_pwd=PASSWORD" -O outfile.htm http://domain.com/index.php

The form is as follows:

<login POST http://domain.com/index.php application/x-www-form-urlencoded
  <TextControl(login_nick=USERNAME)>
  <PasswordControl(login_pwd=PASSWORD)>
  <CheckboxControl(login_auto=[1])>
  <SubmitButtonControl(<None>=) (readonly)>>

Setting the appropriate values ​​and submitting the form is not a problem, but this eliminates the "action = login" -part.

response = self.browser.open(self.url+"/index.php")
self.browser.select_form(name="login")

self.browser["login_nick"] = self.encoded_username
self.browser["login_pwd"] = self.encoded_password

self.browser.method = "POST"

response = self.browser.open(self.browser.submit())

print (response.read())

Now the question arises: how to add a part action=login?

: , action . TCP Wireshark, POST , . , urlencoding ( , -). , Γ…, URL% C5. , , % 25C5. ?

EDIT: , , , . .

+5
1

, , , . (, , , , ).

import mechanize

self.browser = mechanize.Browser()
self.browser.open(self.url)
self.browser.select_form(name="login")

self.browser["login_nick"] = self.username
self.browser["login_pwd"] = self.password
self.browser.new_control("HIDDEN", "action", {})
control = self.browser.form.find_control("action")
control.readonly = False
self.browser["action"] = "login"
self.browser.method = "POST"
self.browser.action = self.url

response = self.browser.submit()
+8

All Articles