def _query(self, type_, searchterm):
        '''Search RateYourMusic.'''

        def match(str_a, str_b):
            '''Return True if str_a and str_b are quite similar.'''
            import difflib
            return difflib.SequenceMatcher(
                None, str_a.lower(), str_b.lower()).quick_ratio() > 0.9

        tree = self._request_html(
            'http://rateyourmusic.com/httprequest',
            {'type': type_, 'searchterm': searchterm, 'rym_ajax_req': 1,
             'page': 1, 'action': 'Search'}, method='POST')
        # get first good enough result
        for result in tree.xpath('//tr[@class="infobox"]'):
            try:
                name = result.xpath('.//a[@class="searchpage"]/text()')[0]
                if type_ in 'ay' and not match(name, searchterm):
                    continue
                elif type_ == 'l':
                    artist = result.xpath(
                        './/td[2]//td[1]/a[@class="artist"]/text()')[0]
                    if not match(artist + ' ' + name, searchterm):
                        continue
                url = result.xpath('.//a[@class="searchpage"]/@href')[0]
            except __HOLE__:
                continue
            return self._scrap_url(url)
        return None
dataset/ETHPy150Open YetAnotherNerd/whatlastgenre/wlg/dataprovider.py/RateYourMusic._query