3

The url that i have to submit to the server looks like this:

www.mysite.com/manager.php?checkbox%5B%5D=5&checkbox%5B%5D=4&checkbox%5B%5D=57&self=19&submit=Go%21

The post data I put it like this:

data = {'checkbox%5B%5D': '4', ....and so on... 'self': '19', 'submit': 'Go%21'}

I encode it:

data = urllib.urlencode(orbs)

and this is how i run it:

resp = mechanize.Request('http://mysite.com/manager.php', data)
cj.add_cookie_header(resp)
res = mechanize.urlopen(resp)
print res.read()

And the error says: That i didnt select any item. How can I do it right without using br.select_form(nr=0) because I have nested forms? Thanks.

2 Answers 2

3

Url encoding is the process of changing string (i.e '[]') into percent-encoded string (i.e '%5B%5D') and url decoding is the opposite operation. So:

checkbox%5B%5D=5&checkbox%5B%5D=4&checkbox%5B%5D=57&self=19&submit=Go%21

is after decoding:

checkbox[]=5&checkbox[]=4&checkbox[]=57&self=19&submit=Go!

In your code you're actually encofing an already-encoded url:

data = {'checkbox%5B%5D': '4', ....and so on... 'self': '19', 'submit': 'Go%21'}
data = urllib.urlencode(orbs)

Instead use decoded data and pass it to urlencode:

data = {'checkbox[]': '4', ....and so on... 'self': '19', 'submit': 'Go!'}
data = urllib.urlencode(orbs)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the complete answer but DJC was faster than you.
2

You double-encoded the checkbox field names; you should use checkbox[] instead of checkbox%5B%5D. Also, because that key name is reused, you probably can't use a dictionary to gather up the arguments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.