python and http POST

Javier Collado javier.collado at gmail.com
Fri Feb 12 02:59:44 EST 2010


Hello,

I haven't used httplib2, but you can certainly use any other
alternative to send HTTP requests:
- urllib/urllib2
- mechanize

With regard to how do you find the form you're looking for, you may:
- create the HTTP request on your own with urllib2. To find out what
variables do you need to post, you can use tamperdata Firefox addon as
suggested (I haven't used that one) or httpfox (I have and it works
great).
- use mechanize to locate the form for you, fill the data in and click
on the submit button.

Additionally, you may wan to scrape some data that may be useful for
your requests. For that BeautifulSoup is good solution (with some
Firebug help to visually locate what you're looking for).

Best regards,
    Javier

P.S. Some examples here:
http://www.packtpub.com/article/web-scraping-with-python
http://www.packtpub.com/article/web-scraping-with-python-part-2

2010/2/11 galileo228 <mattbarkan at gmail.com>:
> Hey All,
>
> Been teaching myself Python for a few weeks, and am trying to write a
> program that will go to a url, enter a string in one of the search
> fields, submit the search, and return the contents of the search
> result.
>
> I'm using httplib2.
>
> My two particular questions:
>
> 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}),
> how do I know what the particular key should be? In other words, how
> do I tell python which form on the web page I'm visiting I'd like to
> fill in? Do I simply go to the webpage itself and look at the html
> source? But if that's the case, which tag tells me the name of the
> key?
>
> 2) Even once python fills in the form properly, how can I tell it to
> 'submit' the search?
>
> Thanks all!
>
> Matt
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list