#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    167
    Rep Power
    11

    send post variables to remote page, access results


    using python, i'd like to send a remote page some form variables (using POST) and get the results returned.

    suggestions?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Regensburg, Germany
    Posts
    147
    Rep Power
    16
    Have a look at the Python Library Reference, chapter 11.6, httplib module . There is an example that does exactly what you want.
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    It would probably be easier to do this using the urllib modules (urllib & urllib2) since they work at a higher level than httplib. You can use these modules together to send (POST) the required info to a web page mimicking a form being submitted and then use urlopen() to read the page from the net like you would a normal file.

    This usually isn't two hard if you know exactly what you need to send, unfortunately since most the the time this isn't the case it may take a little trial and error.

    Anyway, heres a small script I wrote a year or so ago, which logs onto devshed and updates the users signature:

    Code:
    #!/usr/bin/env python
    
    import urllib, urllib2
    
    def update(link, username, password, email, signature):
    	
    	param1 = urllib.urlencode({'action': 'login', 'username': username, 'password': password}) 
    	param2 = urllib.urlencode({'action': 'updateprofile', 'email': email, 'emailconfirm': email, 'signature': signature}) 
     
    	cookie = urllib.urlopen(link, param1).info()['Set-Cookie'] 
    	cookie = [c for c in cookie.split() if c.endswith(';')][::2]
     
    	urllib.urlopen(urllib2.Request(link, param2, {'Cookie': ''.join(cookie)}))
    	
    update('http://forums.devshed.com/member.php', 'username', 'password', 'somone@somewhere.com', 'new signature text')
    Note that this script was tested before Devshed updated it's forum software so there is a chance that this may not work anymore but as an example it's not a bad one .

    Hope this helps

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo