By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,563 Members | 1,280 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,563 IT Pros & Developers. It's quick & easy.

How to submit webform using ClientForm

P: 22
Hi,
After much research and help from forums, i have the following. Using HTMLParser to parse thru html pages and then finally reaching a webpage where i have to check all the checkboxes and then click the 'Deploy' button. Used ClientForm to do this. But i am getting some HTTP version error

Expand|Select|Wrap|Line Numbers
  1. URL = "http://10.47.42.27:8080/cruisecontrol"
  2.  
  3. #from urllib2 import urlopen
  4. from HTMLParser import HTMLParser
  5.  
  6. import re
  7. import ClientForm
  8. import urllib2
  9.  
  10. # Fetching links using HTMLParser
  11. def get_links(url):
  12.     parser = MyHTMLParser()
  13.     parser.feed(urlopen(url).read())
  14.     parser.close()
  15.     return parser.links
  16.  
  17. # Build url for Deploy page
  18. def get_deploy_url():
  19.     url = URL + "/buildresults/Poker-TTM_%s_nightly_build" % branch
  20.     print url
  21.     for link in get_links(url):
  22.         if link["href"].startswith("Deploy"):
  23.             return "%s/%s" % (URL, link["href"])
  24.  
  25. # Build url for Destination page
  26. def get_destination_url():
  27.     url = get_deploy_url()
  28.     print url
  29.     destination_re = re.compile(r"%s" % destination)
  30.     for link in get_links(url):
  31.         if destination_re.search(link["href"]):
  32.             return "http://10.47.42.27:8080/cruisecontrol/" + link["href"]
  33.         print link["href"]
  34.  
  35. # Parsing HTML pages 
  36. class MyHTMLParser(HTMLParser):
  37.     def __init__(self, *args, **kwd):
  38.         HTMLParser.__init__(self, *args, **kwd)
  39.         self.links = []
  40.  
  41.     def handle_starttag(self, tag, attrs):
  42.         if tag == "a":
  43.             attrs = dict(attrs)
  44.             if "href" in attrs:
  45.                 self.links.append(dict(attrs))
  46.  
  47.     def handle_endtag(self, tag):
  48.         pass
  49.  
  50. if __name__ == "__main__":
  51.     # Read the branch name and the test destination to deploy on
  52.     lines = [x.split(':') for x in open("branch_dest.txt")]
  53.     print lines
  54.     branch = "%s" % lines[0][1].strip()
  55.     print branch
  56.     destination = "%s" % lines[1][1].strip()
  57.     print destination
  58.  
  59.     final_url = get_destination_url()
  60.     if final_url is None:
  61.         print "Cannot deploy here"
  62.     else:
  63.         print final_url
  64.         request = urllib2.Request("%s" % final_url)
  65.         response = urllib2.urlopen(request)
  66.         forms = ClientForm.ParseResponse(response, backwards_compat = False)
  67.         response.close()
  68.         form = forms[0]
  69.         print form
  70.         form.find_control("all_top").items[0].selected = True
  71.         form.find_control("client.POK_code").items[0].selected = True
  72.         form.find_control("client.SVS_code").items[0].selected = True
  73.         form.find_control("client.PAT_code").items[0].selected = True
  74.         form.find_control("client.POK_code_gms").items[0].selected = True
  75.         form.find_control("client.POK_code_gms_cpn").items[0].selected = True
  76.         form.find_control("client.POK_code_mini").items[0].selected = True
  77.         form.find_control("client.LTM_code").items[0].selected = True
  78.         form.find_control("client.LTM_tot_code").items[0].selected = True
  79.         form.find_control("client.POK_code_paradise").items[0].selected = True
  80.         form.find_control("client.POK_code_forfun").items[0].selected = True
  81.         form.find_control("client.POK_code_pokerheaven").items[0].selected = True
  82.         form.find_control("client.POK_code_totalpoker").items[0].selected = True
  83.         form.find_control("client.POK_code_las").items[0].selected = True
  84.         form.find_control("client.POK_code_italian").items[0].selected = True
  85.         form.find_control("client.POK_code_bulgarian").items[0].selected = True
  86.         form.find_control("client.POK_code_finnish").items[0].selected = True
  87.         form.find_control("client.POK_code_danish").items[0].selected = True
  88.         form.find_control("client.POK_code_french").items[0].selected = True
  89.         form.find_control("client.POK_code_greek").items[0].selected = True
  90.         form.find_control("client.POK_code_german").items[0].selected = True
  91.         form.find_control("client.POK_code_croatian").items[0].selected = True
  92.         form.find_control("client.POK_code_polish").items[0].selected = True
  93.         form.find_control("client.POK_code_portuguese").items[0].selected = True
  94.         form.find_control("client.POK_code_romanian").items[0].selected = True
  95.         form.find_control("client.POK_code_russian").items[0].selected = True
  96.         form.find_control("client.POK_code_slovak").items[0].selected = True
  97.         form.find_control("client.POK_code_spanish").items[0].selected = True
  98.         form.find_control("client.POK_code_czech").items[0].selected = True
  99.         form.find_control("client.POK_code_swedish").items[0].selected = True
  100.         form.find_control("client.POK_code_hungarian").items[0].selected = True
  101.         form.find_control("client.POK_code_turkish").items[0].selected = True
  102.         form.find_control("client.POK_code_albanian").items[0].selected = True
  103.         form.find_control("client.POK_code_austrian").items[0].selected = True
  104.         form.find_control("client.POK_code_brazilian").items[0].selected = True
  105.         form.find_control("all").items[0].selected = True
  106.         print form
  107.  
  108.         ##request2 = form.click()
  109.         try:
  110.             response2 = urllib2.urlopen(request2)
  111.         except urllib2.HTTPError, response2:
  112.             pass
  113.  
  114.         print response2.geturl()
  115.         print response2.read()
  116.         response2.close()
  117.  
Below is the error

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\deploy_input_clientform.py", line 65, in <module>
  3.     response = urllib2.urlopen(request)
  4.   File "C:\Python26\lib\urllib2.py", line 126, in urlopen
  5.     return _opener.open(url, data, timeout)
  6.   File "C:\Python26\lib\urllib2.py", line 397, in open
  7.     response = meth(req, response)
  8.   File "C:\Python26\lib\urllib2.py", line 510, in http_response
  9.     'http', request, response, code, msg, hdrs)
  10.   File "C:\Python26\lib\urllib2.py", line 435, in error
  11.     return self._call_chain(*args)
  12.   File "C:\Python26\lib\urllib2.py", line 369, in _call_chain
  13.     result = func(*args)
  14.   File "C:\Python26\lib\urllib2.py", line 518, in http_error_default
  15.     raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
  16. HTTPError: HTTP Error 505: HTTP Version Not Supported
  17.  
May 17 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.