Added html parsing to remove returned scripts, added logo
parent
b11fc5fe67
commit
4636b0f695
|
@ -2,4 +2,5 @@ venv/
|
|||
__pycache__/
|
||||
*.pyc
|
||||
*.pem
|
||||
*.xml
|
||||
run.sh
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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;
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 8.9 KiB |
|
@ -0,0 +1,14 @@
|
|||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
|
||||
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
|
||||
<ShortName>[SNK]</ShortName>
|
||||
<Description>[Search engine full name and summary]</Description>
|
||||
<InputEncoding>[UTF-8]</InputEncoding>
|
||||
<Image width="16" height="16" type="image/x-icon">[https://example.com/favicon.ico]</Image>
|
||||
<Url type="text/html" template="[searchURL]">
|
||||
<Param name="[key name]" value="{searchTerms}"/>
|
||||
<!-- other Params if you need them… -->
|
||||
<Param name="[other key name]" value="[parameter value]"/>
|
||||
</Url>
|
||||
<Url type="application/x-suggestions+json" template="[suggestionURL]"/>
|
||||
<moz:SearchForm>[https://example.com/search]</moz:SearchForm>
|
||||
</OpenSearchDescription>
|
|
@ -1,8 +1,11 @@
|
|||
|
||||
<link rel="search" href="/static/opensearch.xml" type="application/opensearchdescription+xml" title="Bloogle Search">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="/static/js/controller.js"></script>
|
||||
<link rel="stylesheet" href="/static/css/main.css">
|
||||
|
||||
<div class="search-container">
|
||||
<img class="logo" src="/static/img/logo.png">
|
||||
<div class="search-fields">
|
||||
<input type="text" id="search-bar">
|
||||
<button type="submit" id="search-submit">Search</button>
|
||||
|
|
Loading…
Reference in New Issue