{"id":4557,"library":"googlesearch-python","title":"Google Search Python Library","description":"googlesearch is a Python library for scraping the Google search engine. It uses `requests` and `BeautifulSoup4` to parse Google's search results. The library is actively maintained with releases addressing changes in Google's search page structure. The current version is 1.3.0, released January 21, 2025.","status":"active","version":"1.3.0","language":"en","source_language":"en","source_url":"https://github.com/Nv7-GitHub/googlesearch","tags":["google","search","scraping","web scraping"],"install":[{"cmd":"pip install googlesearch-python","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"Used for making HTTP requests to Google's search engine.","package":"requests","optional":false},{"reason":"Used for parsing the HTML content of Google's search results.","package":"BeautifulSoup4","optional":false}],"imports":[{"note":"The `search` function is the primary entry point for performing Google searches. Directly importing `googlesearch` as a module or attempting to import from a package named `google` (which is a different library) will lead to `ModuleNotFoundError` or incorrect functionality.","wrong":"from google import search","symbol":"search","correct":"from googlesearch import search"}],"quickstart":{"code":"from googlesearch import search\n\nquery = \"latest Python news\"\n\n# The 'pause' parameter helps avoid IP blocks from Google by adding a delay between requests.\n# 'num_results' specifies how many unique URLs to return.\nresults = list(search(query, num_results=5, lang=\"en\", pause=2))\n\nif results:\n    print(f\"Top 5 results for '{query}':\")\n    for i, url in enumerate(results):\n        print(f\"{i+1}. {url}\")\nelse:\n    print(f\"No results found for '{query}'.\")\n\n# To get more detailed information (title, URL, description), use 'advanced=True'\n# from googlesearch import search, SearchResult\n# adv_results = list(search(query, advanced=True, num_results=3, pause=2))\n# if adv_results:\n#     print(\"\\nAdvanced search results:\")\n#     for i, res in enumerate(adv_results):\n#         print(f\"{i+1}. Title: {res.title}\")\n#         print(f\"   URL: {res.url}\")\n#         print(f\"   Description: {res.description}\")","lang":"python","description":"Performs a Google search for a given query and prints the top 5 unique URLs. It demonstrates how to use the `pause` parameter to prevent IP blocking and includes a commented section for retrieving `advanced` search results with titles and descriptions."},"warnings":[{"fix":"Upgrade to the latest version (`1.3.0` or newer). Version `1.3.0` specifically addressed issues by updating the parsing logic and using a 'Lynx' user-agent to bypass Google's changes. Regular updates are recommended as Google's layout can change without notice.","message":"Google frequently updates its search page's HTML structure, which can break the library's scraping logic, leading to empty results or parsing failures.","severity":"breaking","affected_versions":"<1.3.0"},{"fix":"Use the `pause` parameter in the `search()` function to introduce delays between requests (e.g., `search(query, pause=2)` for a 2-second delay). For high-volume or commercial scraping, consider rotating proxies or Google's official Custom Search API.","message":"Automated searches are often detected and throttled or blocked by Google, leading to HTTP 429 (Too Many Requests) errors, captchas, or empty results.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you install the correct package using `pip install googlesearch-python` and import it with `from googlesearch import search`. Verify the installed package using `pip show googlesearch-python`.","message":"There are multiple Python packages with similar names (`google`, `python-googlesearch`, `googlesearch-python`), leading to `ModuleNotFoundError` if the wrong one is installed or imported.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To retrieve more detailed information (title, URL, description), pass `advanced=True` to the `search()` function. This will yield `SearchResult` objects with the desired attributes.","message":"By default, the `search()` function yields only URLs. Users expecting titles or descriptions will find these missing from the results.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}