473,406 Members | 2,467 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,406 software developers and data experts.

How to search text on an html page

22
Hi,
I want to search for a particular text on an html page ---> Build Complete
Further execution should be only if the build is successful which is denoted by the text 'Build Complete' on the webpage.

Expand|Select|Wrap|Line Numbers
  1. URL = "http://11.12.13.27:8080/cruisecontrol"
  2.  
  3. from urllib2 import urlopen
  4. from HTMLParser import HTMLParser
  5.  
  6. import re
  7.  
  8. # Fetching links using HTMLParser
  9. def get_links(url):
  10.     parser = MyHTMLParser()
  11.     parser.feed(urlopen(url).read())
  12.     parser.close()
  13.     return parser.links
  14.  
  15. # Build url for Deploy page
  16. def get_deploy_url():
  17.     url = URL + "/buildresults/Poker-TTM_%s_nightly_build" % branch
  18.     print url
  19.     check_re = re.compile(r"/Build Complete/")
  20.     print check_re
  21.     if check_re.search(url):
  22.         print "hello"
  23.         for link in get_links(url):
  24.             if link["href"].startswith("Deploy"):
  25.                 return "%s/%s" % (URL, link["href"])
  26.         print link["href"]
  27.  
  28. # Build url for Destination page
  29. def get_destination_url():
  30.     url = get_deploy_url()
  31.     print url
  32.     destination_re = re.compile(r"%s" % destination)
  33.     for link in get_links(url):
  34.         if destination_re.search(link["href"]):
  35.             return "http://11.12.13.27:8080/cruisecontrol/" + link["href"]
  36.  
  37. # Parsing HTML pages 
  38. class MyHTMLParser(HTMLParser):
  39.     def __init__(self, *args, **kwd):
  40.         HTMLParser.__init__(self, *args, **kwd)
  41.         self.links = []
  42.  
  43.     def handle_starttag(self, tag, attrs):
  44.         if tag == "a":
  45.             attrs = dict(attrs)
  46.             if "href" in attrs:
  47.                 self.links.append(dict(attrs))
  48.  
  49.     def handle_endtag(self, tag):
  50.         pass
  51.  
  52. if __name__ == "__main__":
  53.     # Read the branch name and the test destination to deploy on
  54.     lines = [x.split(':') for x in open("branch_dest.txt")]
  55.     print lines
  56.     branch = "%s" % lines[0][1].strip()
  57.     print branch
  58.     destination = "%s" % lines[1][1].strip()
  59.     print destination
  60.  
  61.     final_url = get_destination_url()
  62.     if final_url is None:
  63.         print "Could not find a destination to deploy"
  64.     else:
  65.         print final_url
  66.  
I am getting the below error

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\deploy_input.py", line 61, in <module>
  3.     final_url = get_destination_url()
  4.   File "C:\deploy_input.py", line 33, in get_destination_url
  5.     for link in get_links(url):
  6.   File "C:\deploy_input.py", line 11, in get_links
  7.     parser.feed(urlopen(url).read())
  8.   File "C:\Python26\lib\urllib2.py", line 126, in urlopen
  9.     return _opener.open(url, data, timeout)
  10.   File "C:\Python26\lib\urllib2.py", line 382, in open
  11.     req.timeout = timeout
  12. AttributeError: 'NoneType' object has no attribute 'timeout'
  13.  
Help!
May 13 '10 #1
0 1085

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

Similar topics

1
by: Sheela | last post by:
Hi all gurus in tha club, I scripted a prog that extract a string from an html page excluding all the tags. The problem is that it works quite slowly and I wanted to know if somebody of us as an...
4
by: Michi | last post by:
I was wondering what the best solution is for making large numbers of TEXT (or BLOB?) fields searchable. For example, if I have a forum, what is the best way to be able to search for specific...
2
by: Brent V | last post by:
Hopefully someone has had to handle this type of situation in .NET before. I have an ASP.NET (VB.NET) that has an interface to an API CGI script program. I send a credit card number, amount, etc to...
5
by: acord | last post by:
Hi, I m getting annoying display problem when placing javascript tags in a html page. Should the javasscript tags placed at the beginning of a html page before anything start? or placed between...
13
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them...
13
by: =?Utf-8?B?S2VzdGZpZWxk?= | last post by:
Hi Our company has a .Net web service that, when called via asp.net web pages across our network works 100%! The problem is that when we try and call the web service from a remote machine, one...
17
by: =?Utf-8?B?Y2F0aGFyaW51cyB2YW4gZGVyIHdlcmY=?= | last post by:
Hello, I have build a website with approximately 30 html-pages. When I search this website in Google, I see the index.html or home.html on this website, but also other html-pages on this...
10
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario -------------...
10
by: jpollack | last post by:
I don't know JavaScript but have been tasked to write a script that will change the value of a Boolean variable to the word "Yes" on a table row. I have been trying to achieve this based on my...
7
by: imtmub | last post by:
I have a page, Head tag Contains many Scripts and style sheet for Menu and Page. This code working fine and displaying menus and page as i wanted. Check this page for reference....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.