1

I am trying to submit the form at http://www.harshtechtalk.com/contact-us-harsh-tech-talk using the following code but no success. Please help!

#!C:/Python27/python.exe

import urllib
import urllib2

def main():
        proxy_info={
                        'user' : 'abc@abc.com',
                        'pass' : 'xyz',
                        'host' : 'xxxxxxxx',
                        'port' : 80
                        }
        proxy_support = urllib2.ProxyHandler({"http" : "http://%(user)s:%(pass)s@%(host)s:%(port)d"
% proxy_info})
        opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
        urllib2.install_opener(opener)
        url = 'http://www.harshtechtalk.com/contact-us-harsh-tech-talk'
        values = {
                        'your-name':'test_name',
                        'your-email':'test@gmail.com',
                        'your-subject':'python_test',
                        'your-message':'test_message'
                        }
        data = urllib.urlencode(values)
        req = urllib2.Request(url,data)
        response = urllib2.urlopen(req)
        the_page = response.read()
        print "done"

if __name__ == '__main__':
        main()

PS - I don't want to use "mechanize" because it doesn't support javascript. Please let me know if there is any other module which I can use to handle dynamic web forms.

theharshest
  • 7,767
  • 11
  • 41
  • 51
  • What does "no success" mean? How are you executing javascript now? – Wooble Sep 14 '11 at 23:08
  • This is the contact form on my blog. So, for any form submission I receive an email. By no success I mean that I didn't get any mail. It works with mechanize as I have tried using it. So, there is no problem with the form. – theharshest Sep 15 '11 at 18:55

1 Answers1

0

Handling AJAX web forms generally requires using selenium so that Python is driving a real web browser with a JavaScript engine installed. Some people also talk about phantomjs but I am not aware of an official Python module for it at this point. See also:

Headless, scriptable Firefox/Webkit on linux?

Community
  • 1
  • 1
Brandon Rhodes
  • 83,755
  • 16
  • 106
  • 147