Hi,
I am a tester and new to python.
The code in bold should execute only if the webpage has the text 'BUILD COMPLETE'. This text is between the <th> tag and this is found using DataParser class.
URL = "http://11.12.13.27:8080/cruisecontrol"
from urllib2 import urlopen
from HTMLParser import HTMLParser
import re
# Fetching links using HTMLParser
def get_links(url):
parser = MyHTMLParser()
parser.feed(urlopen(url).read())
parser.close()
return parser.links
# Build url for Deploy page
def get_deploy_url():
url = URL + "/buildresults/xxx_%s_nightly_build" % branch
print url
[B]parser = DataParser()
parser.feed(urlopen(url).read())
parser.close()
print data #Here it displays 0
if data.find("/BUILD COMPLETE/") > 0:
for link in get_links(url):
if link["href"].startswith("Deploy"):
return "%s/%s" % (URL, link["href"])
else:
print "Build Failed"[/B]
# Build url for Destination page
def get_destination_url():
url = get_deploy_url()
print url
destination_re = re.compile(r"%s" % destination)
for link in get_links(url):
if destination_re.search(link["href"]):
return "http://11.12.13.27:8080/cruisecontrol/" + link["href"]
# Parsing HTML pages
class MyHTMLParser(HTMLParser):
def __init__(self, *args, **kwd):
HTMLParser.__init__(self, *args, **kwd)
self.links = []
def handle_starttag(self, tag, attrs):
if tag == "a":
attrs = dict(attrs)
if "href" in attrs:
self.links.append(dict(attrs))
def handle_endtag(self, tag):
pass
# To find all text in the HTML table
[B]class DataParser(HTMLParser):
def handle_data(self, data):
data = data.strip()
if data:
print data[/B] #This is displaying all the text including the text BUILD COMPLETE
if __name__ == "__main__":
# Read the branch name and the test destination to deploy on
lines = [x.split(':') for x in open("branch_dest.txt")]
print lines
branch = "%s" % lines[0][1].strip()
print branch
destination = "%s" % lines[1][1].strip()
print destination
final_url = get_destination_url()
if final_url is None:
print "Could not find a destination to deploy"
else:
print final_url
Below is the error i am getting
Traceback (most recent call last):
File "C:\build_complete testing.py", line 76, in <module>
final_url = get_destination_url()
File "C:\build_complete testing.py", line 38, in get_destination_url
url = get_deploy_url()
File "C:\build_complete testing.py", line 29, in get_deploy_url
if data.find("/BUILD COMPLETE/") > 0:
AttributeError: 'int' object has no attribute 'find'
Please help