38def response(resp):
39 results = []
40
41 dom = html.fromstring(resp.text)
42
43 search_res = dom.xpath('//div[@class="one_result"]')
44
45
46 if not search_res:
47 return []
48
49
50 for result in search_res:
51 link = result.xpath('.//div[@class="torrent_name"]//a')[0]
52 href = urljoin(url, link.attrib.get('href'))
53 title = extract_text(link)
54
55 excerpt = result.xpath('.//div[@class="torrent_excerpt"]')[0]
56 content = html.tostring(excerpt, encoding='unicode', method='text', with_tail=False)
57
58 content = content.strip().replace('\n', ' | ')
59 content = ' '.join(content.split())
60
61 filesize = result.xpath('.//span[@class="torrent_size"]/text()')[0].split()[0]
62 filesize_multiplier = result.xpath('.//span[@class="torrent_size"]/text()')[0].split()[1]
63 files = (result.xpath('.//span[@class="torrent_files"]/text()') or ['1'])[0]
64
65
66 filesize = get_torrent_size(filesize, filesize_multiplier)
67
68
69 try:
70 files = int(files)
71 except:
72 files = None
73
74 magnetlink = result.xpath('.//div[@class="torrent_magnet"]//a')[0].attrib['href']
75
76
77 results.append(
78 {
79 'url': href,
80 'title': title,
81 'content': content,
82 'filesize': filesize,
83 'files': files,
84 'magnetlink': magnetlink,
85 'template': 'torrent.html',
86 }
87 )
88
89
90 return results