From 4636b0f69554642ba2dd25883e032c483ab7933d Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Thu, 23 Jan 2020 06:19:17 +0000 Subject: [PATCH] Added html parsing to remove returned scripts, added logo --- .gitignore | 1 + app/routes.py | 34 ++++++++++++++++++++++++++++++--- app/static/css/main.css | 7 +++++++ app/static/img/logo.png | Bin 0 -> 9122 bytes app/static/opensearch.template | 14 ++++++++++++++ app/templates/index.html | 3 +++ 6 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 app/static/img/logo.png create mode 100644 app/static/opensearch.template diff --git a/.gitignore b/.gitignore index 1c1abdd..82de859 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ venv/ __pycache__/ *.pyc *.pem +*.xml run.sh diff --git a/app/routes.py b/app/routes.py index 507a578..6c1f610 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,7 +1,9 @@ from app import app +from bs4 import BeautifulSoup from flask import request, redirect, Response, render_template import os import pycurl +import re from .url import url_parse from io import BytesIO @@ -24,7 +26,12 @@ def search(): if 'tbm' in request.args: tbm = '&tbm=' + request.args.get('tbm') + start = '' + if 'start' in request.args: + start = '&start=' + request.args.get('start') + user_agent = request.headers.get('User-Agent') + full_query = url_parse(q) + tbm + start google_ua = DESKTOP_UA if 'Android' in user_agent or 'iPhone' in user_agent: @@ -32,17 +39,33 @@ def search(): b_obj = BytesIO() crl = pycurl.Curl() - crl.setopt(crl.URL, 'https://www.google.com/search?q=' + url_parse(q) + tbm) + crl.setopt(crl.URL, 'https://www.google.com/search?gbv=1&q=' + full_query) crl.setopt(crl.USERAGENT, google_ua) crl.setopt(crl.WRITEDATA, b_obj) crl.perform() crl.close() - get_body = b_obj.getvalue() - return render_template('search.html', response=get_body.decode("utf-8", 'ignore')) + get_body = b_obj.getvalue().decode('utf-8', 'ignore') + get_body = get_body.replace('data-src', 'src').replace('.001', '1').replace('visibility:hidden', 'visibility:visible').replace('>G<', '>Bl<') + + pattern = re.compile('4285f4|ea4335|fbcc05|34a853|fbbc05', re.IGNORECASE) + get_body = pattern.sub('0000ff', get_body) + + soup = BeautifulSoup(get_body, 'html.parser') + try: + for script in soup("script"): + script.decompose() + soup.find('div', id='sfooter').decompose() + except Exception: + pass + + return render_template('search.html', response=soup) @app.route('/url', methods=['GET']) def url(): + if 'url' in request.args: + return redirect(request.args.get('url')) + q = request.args.get('q') if len(q) > 0 and 'http' in q: return redirect(q) @@ -50,5 +73,10 @@ def url(): return render_template('error.html') +@app.route('/imgres') +def imgres(): + return redirect(request.args.get('imgurl')) + + if __name__ == '__main__': app.run(debug=True, host='0.0.0.0') diff --git a/app/static/css/main.css b/app/static/css/main.css index d514443..120b572 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -5,6 +5,13 @@ body { font-family: 'Open Sans', sans-serif; } +.logo { + width: 80%; + display: block; + margin: auto; + padding-bottom: 10px; +} + .search-container { width: 80%; position: absolute; diff --git a/app/static/img/logo.png b/app/static/img/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..9c1701b65f3c73ca2438db937bb59167b374e134 GIT binary patch literal 9122 zcmX|n2V4`+6Yr(d5%@`w7K$JUNRcj0x)cSJA}vbj1Q4mx5GiwxBJ6Jf2$2VXKPUju z$OQnNz{jmt7w8r6n`Xuaz|rxqr0w|wdI@8IkZFybN4`^Fxf)A37jB}TVy^dtS7#a1Lv&85^ee=r!ha9e&i zE5gUcyh!`YA5M$mM_xBK4A*D5=Zel)In8pyRL>jz$CEVsS|)BOa9Vg1;*pp)v%PmM zWZGrr*JF*qpZl+NzXybcOuv5pYEgFu-fkXa&-NLiU9rC>LY0tb&1Eu&s#=gq6PYu_ zF~})3o=LL_7v97h-JL7RFx?OFCY`-+kWF!q83v6VXQcb|ZA$uF`?rYlEMh{Tmp^Oz zdh_E?@Pmv&b69r06$l^9`f4m|7roZz;S7$>dt%(^R4mWD9x4;Hf`|0bP?H=+lema~Bn+BCa z|40&GyuKb<6gm9s|Hp-4%E^aM?Jn!9QqXV4N@hQh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&urS<7v42l&0F|Bu! zeDT1Mt*(rqdaQjWS1B{8!9?!^Sf^U-EJ*>GD!Q{3i3#|phbQTU3H!{+9~ZBN?LPd9 zd}M1Rc$21tKZq6v0dy{#23d057`bK z%T3EB$>UWOPn;RHaS?go{o~*92B4IOl&ya1OE~-dd70{@W6|@VZ*X)J9GtY(dyno| zHu`P<9lc1)&wPSx;?ybdZgb}(B_o|1vK9VyATJ-V9v!^(H8*a$@1`f_WZL?Tk6-CE z*7^hx8;y`i>hNRw8_|(I@hlJvh)R_2LtDM_w$vkPx# literal 0 HcmV?d00001 diff --git a/app/static/opensearch.template b/app/static/opensearch.template new file mode 100644 index 0000000..601b7e1 --- /dev/null +++ b/app/static/opensearch.template @@ -0,0 +1,14 @@ + + [SNK] + [Search engine full name and summary] + [UTF-8] + [https://example.com/favicon.ico] + + + + + + + [https://example.com/search] + diff --git a/app/templates/index.html b/app/templates/index.html index a81c784..efb143e 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -1,8 +1,11 @@ + +
+