473,383 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to submit webform using ClientForm

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
0 1735

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

Similar topics

1
by: VB Programmer | last post by:
I created a VB.NET user control which uses a nonmanaged ActiveX control. I built it as 'mycontrol.dll'. In my ASP.NET webform I'm trying to add the new control to my Toolbox, but when I goto...
9
by: Peter Afonin | last post by:
Hello: I need to clear all textboxes on the webform after the data has been submitted. How can I do this in one step? I found a C# code: // get a reference to your form control Control frm...
1
by: timmso | last post by:
If I create a webform in notepad (save it with an .aspx extension), I can see the VB.Net code along with the ASP.Net code in one file. If I create an Asp.Net web application and add a web form...
1
by: ReidarT | last post by:
I am trying to get control on where the user moves around in a webform especially after fields with autopostback. I have found a C# page with some of this stuff, but when I have converted it to...
0
by: Rocky | last post by:
How can I set a static ip address, subnet mask, default gateway, dns servers, and dns suffix via a asp.net webform using vb.net code on a local machine?
0
by: Rocky | last post by:
How can list and delete user profiles on a remote machine that is in AD via a asp.net webform using vb.net?
0
by: emiliano | last post by:
Hey guys, i was just googling some information about how to use the ClientForm package with a page which requires HTTP basic authentication and i got here :P ... So here is the problem, lets see if...
3
by: preethamsaroja | last post by:
can anybody plz, send m the code for menus& submenus or else tell m how to write code in webform using vb.net..............plz its very urgent.....
2
by: hp1980 | last post by:
Hi, I'm writing a web automation script using ClientForm and urlgrabber. I use urlgrabber because I need the "http keepalive" which doesn't exist in urllib2. I'm facing a problem, the...
0
by: skiani | last post by:
Hi, I'm trying to automate downloading a file from a website. The site has a cookie based authentication so I use ClientCookie to first login then I fillout the form with ClientForm successfully....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.