Python HTTP POST

M

Matt Graves

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)
 
J

John Gordon

In said:
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()
 
A

alex23

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.
 
S

Sivaram Neelakantan

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
--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top