Re: Convert dictionary to HTTP POST

Discussion in 'Python' started by Laszlo Zsolt Nagy, Mar 3, 2006.

  1. >
    >
    >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'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's cat" in "Bessy's cat"?

    Thanks,

    Laszlo
     
    Laszlo Zsolt Nagy, Mar 3, 2006
    #1
    1. Advertising

  2. Laszlo Zsolt Nagy enlightened us with:
    > The values of some inputs are encoded using html entities. How can
    > I decode a string like "Bessy's cat" in "Bessy's cat"?


    This should help:
    http://docs.python.org/lib/module-htmlentitydefs.html

    Sybren
    --
    The problem with the world is stupidity. Not saying there should be a
    capital punishment for stupidity, but why don't we just take the
    safety labels off of everything and let the problem solve itself?
    Frank Zappa
     
    Sybren Stuvel, Mar 3, 2006
    #2
    1. Advertising

  3. Laszlo Zsolt Nagy

    Kent Johnson Guest

    Kent Johnson, Mar 3, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    6,080
    Tor Iver Wilhelmsen
    Aug 29, 2005
  2. James
    Replies:
    3
    Views:
    16,638
    Roedy Green
    Nov 25, 2005
  3. Laszlo Zsolt Nagy

    Convert dictionary to HTTP POST

    Laszlo Zsolt Nagy, Mar 3, 2006, in forum: Python
    Replies:
    1
    Views:
    865
    Sybren Stuvel
    Mar 3, 2006
  4. Laszlo Zsolt Nagy

    Re: Convert dictionary to HTTP POST

    Laszlo Zsolt Nagy, Mar 3, 2006, in forum: Python
    Replies:
    0
    Views:
    354
    Laszlo Zsolt Nagy
    Mar 3, 2006
  5. ColinK
    Replies:
    0
    Views:
    595
    ColinK
    Jul 15, 2007
Loading...

Share This Page