![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programming Guru
![]() |
Submitting POST data
Okay, so using urllib2 I can send GET data easily to a website like so:
import urllib2 opener = urllib2.build_opener() page = opener.open( 'http://jammersbase.ath.cx?error=Sent%20some%20get%20data...' ).read() print "Sent GET data successfully!" But how do you suppose I sent POST data to a website? I need this so I can login to a website using an automated script. Will urllib2 store your session as if you're browing directly on the site, or is there some fancy thing I need to do for that? :o |
|
|
|
|
|
#2 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
I believe you would use the optional data parameter.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#3 | |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
As Dameon said, pass the POST data as the second parameter to urlopen. You can either construct the POST query string by yourself, or use urllib.urlencode to construct the query string from you from a dictionary, e.g
p = urllib.urlopen("http://foo.com/", urllib.urlencode({"foo" : "bar", "bar" : "baz"}))Quote:
|
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
Oooh! Pretty!! ^^;;
The cookie thing will need some experimentin' with though. Thanks. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|