def search_symbol(self, phrase, headn=None ): callback = "YAHOO.Finance.SymbolSuggest.ssCallback" url = self.url_symbol % urllib.urlencode({\ 'query' : phrase.strip(), 'callback' : callback }) html = self.cache.perform_request( url ).\ replace(callback,'').strip(')(') data = cjson.decode(html)['ResultSet']['Result'] symbols = [ d['symbol'] for d in data ] return( qutils.head_list( symbols, headn ))
def search_symbol(self, phrase, headn=None): # return google symbols for query phrase, may return more than 1 result! # @param phrase: string submitted to google.finance # @param headn: limit number of answer. If 1, just return a string, not # a list phrase = phrase.rstrip() url = self.url_symbol % urllib.urlencode( {'q':phrase } ) bs = BeautifulSoup( self.cache.perform_request( url ) ) nodes = bs.findAll( 'td', {'class':re.compile('localName.*')} ) nodes = [ n.find('a') for n in nodes ] nodes = [ n for n in nodes if n ] links = [ n['href'].split('q=') for n in nodes if n.has_key('href') ] syms = [ s[-1] for s in links if len(s)==2 ] return qutils.head_list( syms, headn )