diff --git a/README.md b/README.md index e43f1bc..a3ba244 100644 --- a/README.md +++ b/README.md @@ -39,4 +39,14 @@ If requesting more than 100 results, googlesearch will send multiple requests to ```python from googlesearch import search search("Google", sleep_interval=5, num_results=200) -``` \ No newline at end of file +``` +If you are using a HTTP Rotating Proxy which requires you to install their CA Certificate, you can simply add `SSL_VERIFY=False` in the `search()` method to avoid SSL Verification. +```python +from googlesearch import search + +proxy = 'http://API:@proxy.host.com:8080/' + +j = search("proxy test", num_results=100, lang="en", proxy=proxy, SSL_VERIFY=False) +for i in j: + print(i) +``` diff --git a/googlesearch/__init__.py b/googlesearch/__init__.py index 74e6564..15e676f 100644 --- a/googlesearch/__init__.py +++ b/googlesearch/__init__.py @@ -6,7 +6,7 @@ import urllib -def _req(term, results, lang, start, proxies, timeout): +def _req(term, results, lang, start, proxies, timeout, SSL_VERIFY): resp = get( url="https://www.google.com/search", headers={ @@ -20,6 +20,7 @@ def _req(term, results, lang, start, proxies, timeout): }, proxies=proxies, timeout=timeout, + verify=SSL_VERIFY, ) resp.raise_for_status() return resp @@ -35,7 +36,7 @@ def __repr__(self): return f"SearchResult(url={self.url}, title={self.title}, description={self.description})" -def search(term, num_results=10, lang="en", proxy=None, advanced=False, sleep_interval=0, timeout=5): +def search(term, num_results=10, lang="en", proxy=None, advanced=False, sleep_interval=0, timeout=5, SSL_VERIFY=None): """Search the Google search engine""" escaped_term = urllib.parse.quote_plus(term) # make 'site:xxx.xxx.xxx ' works. @@ -53,7 +54,7 @@ def search(term, num_results=10, lang="en", proxy=None, advanced=False, sleep_in while start < num_results: # Send request resp = _req(escaped_term, num_results - start, - lang, start, proxies, timeout) + lang, start, proxies, timeout, SSL_VERIFY) # Parse soup = BeautifulSoup(resp.text, "html.parser")