(query)
return res
Search in bing
Search in bing
Search in bing
def search(query):
        """
        Search in bing
        """
        # FIXME : change default UA
        r = requests.get(
            "https://www.bing.com/search",
            params = {'q': query }
        )
        soup = BeautifulSoup(r.text, 'lxml')
        res = []
        divs = soup.find_all('li', class_='b_algo')
        for d in divs:
            data = {
                'name': d.a.text,
                'url': d.a['href'],
                'text': d.p.text
            }
            attribution = d.find('div', class_='b_attribution')
            # Check if cache infos in attribute
            if 'u' in attribution.attrs:
                b = attribution['u'].split('|')
                data['cache'] = "http://cc.bingj.com/cache.aspx?d=%s&w=%s" % (
                    b[2],
                    b[3]
                )
            res.append(data)
        return res
def search ( query ) : # FIXME : change default UA r = requests . get ( "https://www.bing.com/search" , params = { 'q' : query } ) soup = BeautifulSoup ( r . text , 'lxml' ) res = [ ] divs = soup . find_all ( 'li' , class_ = 'b_algo' ) for d in divs : data = { 'name' : d . a . text , 'url' : d . a [ 'href' ] , 'text' : d . p . text } attribution = d . find ( 'div' , class_ = 'b_attribution' ) # Check if cache infos in attribute if 'u' in attribution . attrs : b = attribution [ 'u' ] . split ( '|' ) data [ 'cache' ] = "http://cc.bingj.com/cache.aspx?d=%s&w=%s" % ( b [ 2 ] , b [ 3 ] ) res . append ( data ) return res