57def response(resp):
58 results = []
59
60 dom = html.fromstring(resp.text)
61
62 for result in dom.xpath(xpath_results):
63
64 filesize = 0
65 magnet_link = ""
66 torrent_link = ""
67
68
69
70 category = eval_xpath_getindex(result, xpath_category, 0, '')
71 if category:
72 category = category.attrib.get('title')
73
74
75 page_a = result.xpath(xpath_title)[0]
76 title = extract_text(page_a)
77
78
79 href = base_url + page_a.attrib.get('href')
80
81 for link in result.xpath(xpath_torrent_links):
82 url = link.attrib.get('href')
83 if 'magnet' in url:
84
85 magnet_link = url
86 else:
87
88 torrent_link = url
89
90
91 seed = int_or_zero(result.xpath(xpath_seeds))
92
93
94 leech = int_or_zero(result.xpath(xpath_leeches))
95
96
97 downloads = int_or_zero(result.xpath(xpath_downloads))
98
99
100
101 filesize = eval_xpath_getindex(result, xpath_filesize, 0, '')
102
103
104 content = 'Category: "{category}". Downloaded {downloads} times.'
105 content = content.format(category=category, downloads=downloads)
106
107 results.append(
108 {
109 'url': href,
110 'title': title,
111 'content': content,
112 'seed': seed,
113 'leech': leech,
114 'filesize': filesize,
115 'torrentfile': torrent_link,
116 'magnetlink': magnet_link,
117 'template': 'torrent.html',
118 }
119 )
120
121 return results