diff --git a/app/filter.py b/app/filter.py
index f10dcf3..859dc6e 100644
--- a/app/filter.py
+++ b/app/filter.py
@@ -42,14 +42,19 @@ class Filter:
if input_form is not None:
input_form['method'] = 'POST'
+ # Ensure no extra scripts passed through
+ for script in soup('script'):
+ script.decompose()
+
+ footer = soup.find('div', id='sfooter')
+ if footer is not None:
+ footer.decompose()
+
return soup
def remove_ads(self, soup):
main_divs = soup.find('div', {'id': 'main'})
- if main_divs is None:
- return
-
- result_divs = main_divs.findAll('div', recursive=False)
+ result_divs = main_divs.find_all('div', recursive=False)
# Only ads/sponsored content use classes in the list of result divs
ad_divs = [ad_div for ad_div in result_divs if 'class' in ad_div.attrs]
@@ -101,19 +106,18 @@ class Filter:
a.decompose()
continue
- if '?q=' not in href:
- continue
-
result_link = urlparse.urlparse(href)
- query_link = parse_qs(result_link.query)['q'][0]
+ query_link = parse_qs(result_link.query)['q'][0] if '?q=' in href else ''
if '/search?q=' in href:
enc_result = Fernet(self.secret_key).encrypt(query_link.encode())
new_search = '/search?q=' + enc_result.decode()
- for param in VALID_PARAMS:
- if param in parse_qs(result_link.query):
- new_search += '&' + param + '=' + parse_qs(result_link.query)[param][0]
+ query_params = parse_qs(urlparse.urlparse(href).query)
+ allowed_params = [_ for _ in query_params if _ in VALID_PARAMS]
+ for param in allowed_params:
+ param_val = query_params[param][0]
+ new_search += '&' + param + '=' + param_val
a['href'] = new_search
continue
@@ -140,18 +144,13 @@ class Filter:
# Add no-js option
if self.nojs:
- nojs_link = soup.new_tag('a')
- nojs_link['href'] = '/window?location=' + query_link
- nojs_link['style'] = 'display:block;width:100%;'
- nojs_link.string = 'NoJS Link: ' + nojs_link['href']
- a.append(BeautifulSoup('