Convert dictionary to HTTP POST

Laszlo Zsolt Nagy gandalf at designaproduct.biz
Fri Mar 3 14:48:44 CET 2006


>
>
>See urllib.urlencode(). No idea why they don't include it in urllib2 as 
>well, but there you go.
>
> >>> from urllib import urlencode
> >>> urlencode({'a':'& "Simple string"', 'b': '<>!@#$%^&*()_+='})
>'a=%26+%22Simple+string%22&b=%3C%3E%21%40%23%24%25%5E%26%2A%28%29_%2B%3D'
> >>>
>  
>
Hmm. urlencode is using quote_plus internally. Looks like there is no 
difference in the encoding of the apostrophe.
I tried to create a very basic form and realized that the problem is NOT 
with the quoting.
I'm writting a program that puts orders into a wholesaler's database.
They do not have a programatic interface, so I have to login and post 
forms using a program.
There are some fields that I must not change, so I have to read the 
value from the HTML source and then post it back.
Here is the problem:

<html>
<body>
<form method="POST">
  <input name="name" value="Bessy&#39;s cat">
  <input type="submit">
</form>
</body>
</html>

The values of some inputs are encoded using html entities.
How can I decode a string like "Bessy&#39;s cat"  in "Bessy's cat"?

Thanks,

   Laszlo




More information about the Python-list mailing list