From d90468c66767909a597a9d1a0791df1c42381901 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Fri, 3 Apr 2020 18:02:45 +0000 Subject: [PATCH] Updated to remove ads, minor renaming refactor --- app/routes.py | 7 ++++++- app/templates/index.html | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/routes.py b/app/routes.py index 7e50425..14b2d30 100644 --- a/app/routes.py +++ b/app/routes.py @@ -70,11 +70,16 @@ def search(): full_query = url_parse(q) + tbm + start + near get_body = send_request(SEARCH_URL + full_query, get_ua(user_agent)) - get_body = get_body.replace('>G<', '>Bl<') + get_body = get_body.replace('>G<', '>Sh<') pattern = re.compile('4285f4|ea4335|fbcc05|34a853|fbbc05', re.IGNORECASE) get_body = pattern.sub('0000ff', get_body) soup = BeautifulSoup(get_body, 'html.parser') + + ad_divs = soup.find('div', {'id':'main'}).findAll('div', {'class':'ZINbbc'}, recursive=False) + for div in ad_divs: + div.decompose() + for a in soup.find_all('a', href=True): href = a['href'] if 'url?q=' in href: diff --git a/app/templates/index.html b/app/templates/index.html index efb143e..d1353a4 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -1,5 +1,5 @@ - +