from . import Searcher, urljoin_partial, ResultItem class SearchEngine(Searcher): #base_url = 'http://new-tor.top' base_url = 'http://rutor.info' search_path = '/search/0/0/100/2/{}' name = 'RuTor.org' icon = 'searcher_rutor.png' def process(self, body): url_constructor = urljoin_partial(self.base_url) rows = list(filter(lambda x: len(x.findall('.//a')) == 3, body.findall('.//tr'))) for r in rows: links = r.findall('.//a') url = url_constructor(links[0].get('href').strip()) title = links[2].text seeders = int(list(r.findall('.//span[@class="green"]')[0].itertext())[0].strip()) leachers = int(list(r.findall('.//span[@class="red"]')[0].itertext())[0].strip()) size = list( list(filter(lambda x: len(list(x.itertext())) == 1 and list(x.itertext())[0].strip().endswith(('GB', 'MB')), r.findall('.//td')) )[0].itertext() )[0].strip() yield ResultItem(url, title, size, seeders, leachers, self.icon, self.cookies, self.base_url)