summaryrefslogtreecommitdiff
path: root/searx/engines/filecrop.py
diff options
context:
space:
mode:
authorAdam Tauber <asciimoo@gmail.com>2014-01-04 14:55:22 -0800
committerAdam Tauber <asciimoo@gmail.com>2014-01-04 14:55:22 -0800
commit27cae541972cabd460142aa3d009ea00c37c29d5 (patch)
tree794d0928f966f9d90603cf4a4354119870329c6d /searx/engines/filecrop.py
parent42c85a094acb77b65a10cda0c6673293aad72ba4 (diff)
parentefb6eca39e9dd851645f76bd72ac076f61a11c09 (diff)
Merge pull request #13 from pw3t/master
Filecrop & Yacy engine
Diffstat (limited to 'searx/engines/filecrop.py')
-rw-r--r--searx/engines/filecrop.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/searx/engines/filecrop.py b/searx/engines/filecrop.py
new file mode 100644
index 000000000..a1a933db9
--- /dev/null
+++ b/searx/engines/filecrop.py
@@ -0,0 +1,73 @@
+from json import loads
+from urllib import urlencode
+from searx.utils import html_to_text
+from HTMLParser import HTMLParser
+
+url = 'http://www.filecrop.com/'
+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'
+
+class FilecropResultParser(HTMLParser):
+ def __init__(self):
+ HTMLParser.__init__(self)
+ self.__start_processing = False
+
+ self.results = []
+ self.result = {}
+
+ self.tr_counter = 0
+ self.data_counter = 0
+
+ def handle_starttag(self, tag, attrs):
+
+ if tag == 'tr':
+ if ('bgcolor', '#edeff5') in attrs or ('bgcolor', '#ffffff') in attrs:
+ self.__start_processing = True
+
+ if not self.__start_processing:
+ return
+
+ if tag == 'label':
+ self.result['title'] = [attr[1] for attr in attrs if attr[0] == 'title'][0]
+ elif tag == 'a' and ('rel', 'nofollow') in attrs and ('class', 'sourcelink') in attrs:
+ if 'content' in self.result:
+ self.result['content'] += [attr[1] for attr in attrs if attr[0] == 'title'][0]
+ else:
+ self.result['content'] = [attr[1] for attr in attrs if attr[0] == 'title'][0]
+ self.result['content'] += ' '
+ elif tag == 'a':
+ self.result['url'] = url + [attr[1] for attr in attrs if attr[0] == 'href'][0]
+
+ def handle_endtag(self, tag):
+ if self.__start_processing is False:
+ return
+
+ if tag == 'tr':
+ self.tr_counter += 1
+
+ if self.tr_counter == 2:
+ self.__start_processing = False
+ self.tr_counter = 0
+ self.data_counter = 0
+ self.results.append(self.result)
+ self.result = {}
+
+ def handle_data(self, data):
+ if not self.__start_processing:
+ return
+
+ if 'content' in self.result:
+ self.result['content'] += data + ' '
+ else:
+ self.result['content'] = data + ' '
+
+ self.data_counter += 1
+
+def request(query, params):
+ params['url'] = search_url.format(query=urlencode({'w' :query}))
+ return params
+
+def response(resp):
+ parser = FilecropResultParser()
+ parser.feed(resp.text)
+
+ return parser.results