Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50798 > unrolled thread

Python HTTP POST

Started byMatt Graves <tunacubes@gmail.com>
First post2013-07-17 11:49 -0700
Last post2013-07-18 12:04 +1000
Articles 5 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  Python HTTP POST Matt Graves <tunacubes@gmail.com> - 2013-07-17 11:49 -0700
    Re: Python HTTP POST John Gordon <gordon@panix.com> - 2013-07-17 20:15 +0000
      Re: Python HTTP POST Joel Goldstick <joel.goldstick@gmail.com> - 2013-07-17 16:26 -0400
      Re: Python HTTP POST Sivaram Neelakantan <nsivaram.net@gmail.com> - 2013-07-18 23:37 +0530
    Re: Python HTTP POST alex23 <wuwei23@gmail.com> - 2013-07-18 12:04 +1000

#50798 — Python HTTP POST

FromMatt Graves <tunacubes@gmail.com>
Date2013-07-17 11:49 -0700
SubjectPython HTTP POST
Message-ID<00ec2f9b-fcae-428c-8932-163e653dd71b@googlegroups.com>
I am going to be creating a python script that will make filling in information at my job easier.

I have all of the information I need... I guess I just need to see it in practice to fully grasp it.

How would I submit a python HTTP POST request to... for example, go to google.com, enter "Pie" into the search box and submit (Search)

[toc] | [next] | [standalone]


#50805

FromJohn Gordon <gordon@panix.com>
Date2013-07-17 20:15 +0000
Message-ID<ks6u11$gk4$1@reader2.panix.com>
In reply to#50798
In <00ec2f9b-fcae-428c-8932-163e653dd71b@googlegroups.com> Matt Graves <tunacubes@gmail.com> writes:

> How would I submit a python HTTP POST request to... for example, go to
> google.com, enter "Pie" into the search box and submit (Search)

Something like this:

import urllib
import urllib2

# the google form search input box is named 'q'
data = { 'q': 'Pie' }

response = urllib2.urlopen('http://google.com', urllib.urlencode(data))
print response.read()

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#50806

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-07-17 16:26 -0400
Message-ID<mailman.4814.1374092817.3114.python-list@python.org>
In reply to#50805

[Multipart message — attachments visible in raw view] — view raw

On Wed, Jul 17, 2013 at 4:15 PM, John Gordon <gordon@panix.com> wrote:

> In <00ec2f9b-fcae-428c-8932-163e653dd71b@googlegroups.com> Matt Graves <
> tunacubes@gmail.com> writes:
>
> > How would I submit a python HTTP POST request to... for example, go to
> > google.com, enter "Pie" into the search box and submit (Search)
>
> Something like this:
>
> import urllib
> import urllib2
>
> # the google form search input box is named 'q'
> data = { 'q': 'Pie' }
>
> response = urllib2.urlopen('http://google.com', urllib.urlencode(data))
> print response.read()
>
> --
> John Gordon                   A is for Amy, who fell down the stairs
> gordon@panix.com              B is for Basil, assaulted by bears
>                                 -- Edward Gorey, "The Gashlycrumb Tinies"
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Many people find urllib and urllib2 to be confusing.  There is a module
called requests which makes this stuff a lot easier.  ymmv

http://docs.python-requests.org/en/latest/

-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#50863

FromSivaram Neelakantan <nsivaram.net@gmail.com>
Date2013-07-18 23:37 +0530
Message-ID<mailman.4844.1374170888.3114.python-list@python.org>
In reply to#50805
On Thu, Jul 18 2013,Joel Goldstick wrote:


[snipped 28 lines]

>
> Many people find urllib and urllib2 to be confusing.  There is a module
> called requests which makes this stuff a lot easier.  ymmv
>
> http://docs.python-requests.org/en/latest/

Yes, please use this instead of the url* ones, easier to work with and
tinker.  I just finished writing a small scraper using it.  The
documentation too is very good.


 sivaram
 -- 

[toc] | [prev] | [next] | [standalone]


#50819

Fromalex23 <wuwei23@gmail.com>
Date2013-07-18 12:04 +1000
Message-ID<ks7i3q$68k$1@dont-email.me>
In reply to#50798
On 18/07/2013 4:49 AM, Matt Graves wrote:
> How would I submit a python HTTP POST request to... for example, go to google.com, enter "Pie" into the search box and submit (Search)

Other replies have suggested how you could do it by building the request 
yourself. Another approach is to interact directly with the form using 
mechanize:

http://wwwsearch.sourceforge.net/mechanize/

Unfortunately this doesn't appear to actually work with Google, as its 
robots.txt won't allow it. But if you're dealing with an intranet-based 
form in your organisation you should be fine.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web