From 9561276a081220c9f3727c6b11eea2541d6d362a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?VincentX0905=28=E7=82=B8=E8=9D=A6=29?= Date: Sun, 25 Feb 2024 19:12:19 +0800 Subject: [PATCH 1/3] Update __init__.py Add Safe Search for this package --- googlesearch/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/googlesearch/__init__.py b/googlesearch/__init__.py index 74e6564..8faf28e 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, safe): resp = get( url="https://www.google.com/search", headers={ @@ -17,6 +17,7 @@ def _req(term, results, lang, start, proxies, timeout): "num": results + 2, # Prevents multiple requests "hl": lang, "start": start, + "safe": safe, }, proxies=proxies, timeout=timeout, @@ -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, safe="active"): """Search the Google search engine""" escaped_term = urllib.parse.quote_plus(term) # make 'site:xxx.xxx.xxx ' works. From 3c18525cc2655e9e91bb628aa2076959ffafcad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?VincentX0905=28=E7=82=B8=E8=9D=A6=29?= Date: Sun, 25 Feb 2024 19:25:20 +0800 Subject: [PATCH 2/3] Update __init__.py Add Safe Search --- googlesearch/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlesearch/__init__.py b/googlesearch/__init__.py index 8faf28e..0d0e669 100644 --- a/googlesearch/__init__.py +++ b/googlesearch/__init__.py @@ -54,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, safe) # Parse soup = BeautifulSoup(resp.text, "html.parser") From 6f5fe300d4cfde477c32cb0be2b586c4faf4cd91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?VincentX0905=28=E7=82=B8=E8=9D=A6=29?= Date: Sun, 25 Feb 2024 19:38:13 +0800 Subject: [PATCH 3/3] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e43f1bc..3a1acdf 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 @@ -39,4 +44,4 @@ 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 +```