@@ -1,85 +0,0 @@
1−from html.parser import HTMLParser
2−from urllib.parse import urlencode
3−
4−
5−url = 'http://www.filecrop.com/'
6−search_url = url + '/search.php?{query}&size_i=0&size_f=100000000&engine_r=1&engine_d=1&engine_e=1&engine_4=1&engine_m=1&pos={index}' # noqa
7−
8−paging = True
9−
10−
11−class FilecropResultParser(HTMLParser): # pylint: disable=W0223 # (see https://bugs.python.org/issue31844)
12−
13− def __init__(self):
14− HTMLParser.__init__(self)
15− self.__start_processing = False
16−
17− self.results = []
18− self.result = {}
19−
20− self.tr_counter = 0
21− self.data_counter = 0
22−
23− def handle_starttag(self, tag, attrs):
24−
25− if tag == 'tr':
26− if ('bgcolor', '#edeff5') in attrs or\
27− ('bgcolor', '#ffffff') in attrs:
28− self.__start_processing = True
29−
30− if not self.__start_processing:
31− return
32−
33− if tag == 'label':
34− self.result['title'] = [attr[1] for attr in attrs
35− if attr[0] == 'title'][0]
36− elif tag == 'a' and ('rel', 'nofollow') in attrs\
37− and ('class', 'sourcelink') in attrs:
38− if 'content' in self.result:
39− self.result['content'] += [attr[1] for attr in attrs
40− if attr[0] == 'title'][0]
41− else:
42− self.result['content'] = [attr[1] for attr in attrs
43− if attr[0] == 'title'][0]
44− self.result['content'] += ' '
45− elif tag == 'a':
46− self.result['url'] = url + [attr[1] for attr in attrs
47− if attr[0] == 'href'][0]
48−
49− def handle_endtag(self, tag):
50− if self.__start_processing is False:
51− return
52−
53− if tag == 'tr':
54− self.tr_counter += 1
55−
56− if self.tr_counter == 2:
57− self.__start_processing = False
58− self.tr_counter = 0
59− self.data_counter = 0
60− self.results.append(self.result)
61− self.result = {}
62−
63− def handle_data(self, data):
64− if not self.__start_processing:
65− return
66−
67− if 'content' in self.result:
68− self.result['content'] += data + ' '
69− else:
70− self.result['content'] = data + ' '
71−
72− self.data_counter += 1
73−
74−
75−def request(query, params):
76− index = 1 + (params['pageno'] - 1) * 30
77− params['url'] = search_url.format(query=urlencode({'w': query}), index=index)
78− return params
79−
80−
81−def response(resp):
82− parser = FilecropResultParser()
83− parser.feed(resp.text)
84−
85− return parser.results