Skip to content

Commit

Permalink
Merge pull request #7 from Mohammed-Ashour/master
Browse files Browse the repository at this point in the history
Added the support for proxies
  • Loading branch information
Nv7-GitHub authored Jun 9, 2021
2 parents f16103f + 2bc0efe commit 058505a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions googlesearch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from requests import get
from bs4 import BeautifulSoup
from requests import get


def search(term, num_results=10, lang="en"):
def search(term, num_results=10, lang="en", proxy=None):
usr_agent = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/61.0.3163.100 Safari/537.36'}
Expand All @@ -12,7 +12,14 @@ def fetch_results(search_term, number_results, language_code):

google_url = 'https://www.google.com/search?q={}&num={}&hl={}'.format(escaped_search_term, number_results+1,
language_code)
response = get(google_url, headers=usr_agent)
proxies = None
if proxy:
if proxy[:5]=="https":
proxies = {"https":proxy}
else:
proxies = {"http":proxy}

response = get(google_url, headers=usr_agent, proxies=proxies)
response.raise_for_status()

return response.text
Expand Down

0 comments on commit 058505a

Please sign in to comment.