Added desktop/mobile agent switching, updated gitignore
parent
11db9fe2d7
commit
a922b42cbd
|
@ -1,3 +1,5 @@
|
||||||
venv/
|
venv/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
|
*.pem
|
||||||
|
run.sh
|
||||||
|
|
|
@ -5,6 +5,9 @@ import pycurl
|
||||||
from .url import url_parse
|
from .url import url_parse
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
MOBILE_UA = 'Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36'
|
||||||
|
DESKTOP_UA = 'Brozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Mobile LizzieMcGuirefox/59.0'
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET'])
|
@app.route('/', methods=['GET'])
|
||||||
def index():
|
def index():
|
||||||
|
@ -21,10 +24,16 @@ def search():
|
||||||
if 'tbm' in request.args:
|
if 'tbm' in request.args:
|
||||||
tbm = '&tbm=' + request.args.get('tbm')
|
tbm = '&tbm=' + request.args.get('tbm')
|
||||||
|
|
||||||
|
user_agent = request.headers.get('User-Agent')
|
||||||
|
|
||||||
|
google_ua = DESKTOP_UA
|
||||||
|
if 'Android' in user_agent or 'iPhone' in user_agent:
|
||||||
|
google_ua = MOBILE_UA
|
||||||
|
|
||||||
b_obj = BytesIO()
|
b_obj = BytesIO()
|
||||||
crl = pycurl.Curl()
|
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?q=' + url_parse(q) + tbm)
|
||||||
crl.setopt(crl.USERAGENT, 'Brozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 LizzieMcGuirefox/59.0')
|
crl.setopt(crl.USERAGENT, google_ua)
|
||||||
crl.setopt(crl.WRITEDATA, b_obj)
|
crl.setopt(crl.WRITEDATA, b_obj)
|
||||||
crl.perform()
|
crl.perform()
|
||||||
crl.close()
|
crl.close()
|
||||||
|
|
Loading…
Reference in New Issue