diff --git a/README.md b/README.md index a3ba244..392f58f 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,11 @@ In addition, you can change the language google searches in. For example, to get from googlesearch import search search("Google", lang="fr") ``` +If you want to turn off the safe search function (this function is on by default), you can do this: +```python +from googlesearch import search +search("Google", safe=None) +``` To extract more information, such as the description or the result URL, use an advanced search: ```python from googlesearch import search @@ -40,6 +45,7 @@ If requesting more than 100 results, googlesearch will send multiple requests to 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 diff --git a/googlesearch/__init__.py b/googlesearch/__init__.py index 15e676f..8795d0e 100644 --- a/googlesearch/__init__.py +++ b/googlesearch/__init__.py @@ -6,7 +6,7 @@ import urllib -def _req(term, results, lang, start, proxies, timeout, SSL_VERIFY): +def _req(term, results, lang, start, proxies, timeout, safe, SSL_VERIFY): resp = get( url="https://www.google.com/search", headers={ @@ -17,6 +17,7 @@ def _req(term, results, lang, start, proxies, timeout, SSL_VERIFY): "num": results + 2, # Prevents multiple requests "hl": lang, "start": start, + "safe": safe, }, proxies=proxies, timeout=timeout, @@ -36,7 +37,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, SSL_VERIFY=None): +def search(term, num_results=10, lang="en", proxy=None, advanced=False, sleep_interval=0, timeout=5, safe="active", SSL_VERIFY=None): """Search the Google search engine""" escaped_term = urllib.parse.quote_plus(term) # make 'site:xxx.xxx.xxx ' works. @@ -54,7 +55,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, SSL_VERIFY) + lang, start, proxies, timeout, safe, SSL_VERIFY) # Parse soup = BeautifulSoup(resp.text, "html.parser")