why this python program does not work?
Question: My python program gives no error but it does not do what it supposed to do
either.  
What could be possibly wrong?  
Could it be that it does not have access to the imported packages?  
What should I do? It is supposed to go to Yahoo! search website and query the
search engine and brings back the results.

**Code** from
[here](http://rosettacode.org/wiki/Yahoo!_search_interface#Python)

    
    
    import urllib
    import re
    
    def fix(x):
        p = re.compile(r'<[^<]*?>')
        return p.sub('', x).replace('&amp;', '&')
    
    class YahooSearch:
        def __init__(self, query, page=1):       
            self.query = query
            self.page = page
            self.url = "http://search.yahoo.com/search?p=%s&b=%s" %(self.query, ((self.page - 1) * 10 + 1))
            self.content = urllib.urlopen(self.url).read()        
    
        def getresults(self):
            self.results = []
    
            for i in re.findall('<a class="yschttl spt" href=".+?">(.+?)</a></h3></div>(.+?)</div>.*?<span class=url>(.+?)</span>', self.content):
    
                title = fix(i[0])
                content = fix(i[1])
                url = fix(i[2])
    
                self.results.append(YahooResult(title, content, url))
    
            return self.results
    
        def getnextpage(self):
            return YahooSearch(self.query, self.page+1)
    
        search_results = property(fget=getresults)
        nextpage = property(fget=getnextpage)
    
    class YahooResult:
        def __init__(self,title,content,url):
            self.title = title
            self.content = content
            self.url = url
    
    # Usage:
    
    x = YahooSearch("test")
    
    for result in x.search_results:
        print result.title
    


Answer: Your regex looks for `<a class="yschttl spt" etc. etc.`, but the html you are
trying to parse actually contains elements that look like `<a id="link-5"
class="yschttl spt" etc. etc.`.

Beside the fact that you should use a HTML-parser (like
[BeatifulSoup](http://pypi.python.org/pypi/BeautifulSoup)) instead of regular
expressions, you can fix your regex by using somthing like `'<a id="link-\d+"
class="yschttl spt" etc. etc.`

