I am trying to search for a text 'BUILD COMPLETE' on a web page. There is some problem with the RE. Please help. I am new to Python and somehow managed to reach to this point of the program.
I am getting Build Failed output even when the webpage has BUILD COMPLETE and DataParser is returning this.
Code:
URL = "http://10.47.42.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
#
def build_check(url):
parser = DataParser()
parser.feed(urlopen(url).read())
parser.close()
return parser.data
# Build url for Deploy page
def get_deploy_url():
url = URL + "/buildresults/Poker-TTM_%s_nightly_build" % branch
print url
#for parser.data in build_check(url):
parser = DataParser()
parser.feed(urlopen(url).read())
parser.close()
parser.data
[B]build_re = re.compile(r"BUILD COMPLETE")
print "before if"
if build_re.search(parser.data):[/B]
print "after if"
for link in get_links(url):
if link["href"].startswith("Deploy"):
return "%s/%s" % (URL, link["href"])
else:
print "Build Failed"
# Build url for Destination page
def get_destination_url():
url = get_deploy_url()
# 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
class DataParser(HTMLParser):
def handle_data(self, data):
self.data = data.strip()
if data:
print self.data
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()
Comment