def searchJoke(query=None): if query: tree = Utils.crawlUrl('http://www.piadasnet.com/index.php?pesquisaCampo=%s&btpesquisa=OK&pesquisaInicio=0' % quote(query.encode('utf-8'))) else: tree = Utils.crawlUrl('http://www.piadasnet.com/') jokeTags = tree.xpath('//p[contains(@class, "piada")]') return map(lambda t: t.text_content(), jokeTags)
def getNasaIOD(): tree = Utils.crawlUrl('http://apod.nasa.gov') imageTags = tree.xpath('//img[contains(@src,"image")]') pTags = tree.xpath('//p') if imageTags and len(pTags) >= 3: result = { 'imageSource': 'http://apod.nasa.gov/%s' % imageTags[0].attrib['src'], 'explanation': pTags[2].text_content() } return result else: return None
def searchBingImage(query): tree = Utils.crawlUrl('http://www.bing.com/images/search?q=%s' % quote(query.encode('utf-8'))) imageTags = tree.xpath('//img[contains(@src, "bing.net")]') imageSources = map(lambda img: img.attrib.get('src'), imageTags) return imageSources
def searchGoogleImage(query): query = query.encode('utf-8') tree = Utils.crawlUrl('https://www.google.com.br/search?site=&tbm=isch&q=%s&oq=%s&tbs=isz:l' % (quote(query), quote(query))) imageTags = tree.xpath('//img[contains(@src, "gstatic")]') imageSources = map(lambda img: img.attrib.get('src'), imageTags) return imageSources