Hi all,

I just started learning Python and Beautiful Soup. I am developing a script to look for particular text "Running" in the HTML. If that text "Running" exits, I would like to print out the keyword "QSAJK". Please see the attached image to visualize. If there is one or more text of "Running", the script should also print out respective keywords. Below is my code to open the webpage and search for the text. How should I modify to fulfill my requirements. Thank you very much in advance.

import time
import urllib2
import re
from BeautifulSoup import BeautifulSoup
from BeautifulSoup import NavigableString

def Check_Tester():

  soup = BeautifulSoup(urllib2.urlopen("http://compat.sing.seagate.com/servlets/ReportMgrSecure?REPORT=rebootManager&RACK=SG-HFT-15&CLOSE=1&ORDERBY=sporder").read())
  Key_Word = soup.findAll('td',text='Running')
  
def main():
  
  Check_Tester()
  
main()

I'm not familiar with Beautiful Soup but I assume that soup (in your code) is a text string. If I'm correct then you want to be using string replace methods:

str.replace(old, new[, count])
Return a copy of the string with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced.

If you have to make sure that your 'Running' is not in the middle of a word (outrunning), or it case is unimportant, or if there are additional considerations then you may have to move up to the re (regular expression) module

re.sub - http://docs.python.org/py3k/library/re.html?highlight=re.#re.sub

I have been using regular expressions for so long in so many languages I can't remember where I learned it. The python docs are the place to start...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.