Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SSL_VERIFY flag #63

Merged
merged 4 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
```
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)
```
7 changes: 4 additions & 3 deletions googlesearch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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")
Expand Down