Skip to content

Commit

Permalink
Added the support for proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed-Ashour committed Apr 19, 2021
1 parent 43e7ab5 commit 08ab8b0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 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,8 @@ 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 = {"https":proxy} if proxy else None
response = get(google_url, headers=usr_agent, proxies=proxies)
response.raise_for_status()

return response.text
Expand Down

0 comments on commit 08ab8b0

Please sign in to comment.