Hi,
Im basically from QA. I have a piece of code in python that parses HTML pages to reach to a specific link on a webpage. The below code gets me the url of the link which needs to be clicked. What code should i write to simulate clicking a link.
URL = "http://11.12.13.27:8080/cruisecontrol"
BRANCH_FILE = "b.txt"
from urllib2 import urlopen
from HTMLParser import HTMLParser
import re
destination_re = re.compile(r"Test 5")
def read_branch():
return open(BRANCH_FILE).read().strip()
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():
branch = read_branch().lower()
url = URL + "/buildresults/abc_%s_nightly_build" % branch
for link in get_links(url):
if link["href"].startswith("Deploy"):
return "%s/%s" % (URL, link["href"])
# Build url for Destination page
def get_destination_url():
url = get_deploy_url()
print url
for link in get_links(url):
if destination_re.search(link["href"]):
return "http://11.12.13.27:8080/cruisecontrol/" + link["href"]
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
if __name__ == "__main__":
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 output i get
http://11.12.13.27:8080/cruisecontrol/DeploySelect.jsp?ArtifactsUrl=artifacts/abc_b_nightly_build/20100506124231
http://11.12.13.27:8080/cruisecontrol/DeployConfig.jsp?name=Test 5&scriptPath=xxxxxxxxxxx
Actually i have a need to simulate clicking Test 5 link on the deployment webpage url. Please help.