From 2adeb6f60b6f981d9cd3665c4c9556024b5a6f15 Mon Sep 17 00:00:00 2001 From: Muktheeswaran <54277855+mukthy@users.noreply.github.com> Date: Fri, 1 Sep 2023 16:55:14 +0530 Subject: [PATCH 1/3] Added SSL_VERIFY flag. Added SSL_VERIFY flag as with some of the proxy providers it throws SSL errors like below: (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)'))) This flag will take "True" or "False" or path-to-ca.crt file. It helps with not installing and configuring the Proxy CA cert. --- googlesearch/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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") From 85fe62c477e49931f0361eb314e6a6081960eef3 Mon Sep 17 00:00:00 2001 From: Muktheeswaran <54277855+mukthy@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:29:13 +0530 Subject: [PATCH 2/3] Update README.md with SSL Verification False. --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e43f1bc..c771a7a 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="nl", proxy=proxy, SSL_VERIFY=False) +for i in j: + print(i) +``` From 2a127f6984f21a7cbf31d52141e44f40f8a2a605 Mon Sep 17 00:00:00 2001 From: Muktheeswaran <54277855+mukthy@users.noreply.github.com> Date: Fri, 1 Mar 2024 05:31:49 +0530 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c771a7a..a3ba244 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ from googlesearch import search proxy = 'http://API:@proxy.host.com:8080/' -j = search("proxy test", num_results=100, lang="nl", proxy=proxy, SSL_VERIFY=False) +j = search("proxy test", num_results=100, lang="en", proxy=proxy, SSL_VERIFY=False) for i in j: print(i) ```