Skip to main content

A Python package to search Google and retrieve filtered links.

Project description

googlespy - Python Google Search Package

googlespy is a powerful Python package that allows you to easily perform Google searches and retrieve filtered search results based on various parameters such as file type, keywords, domains, language, and more. It's designed to be flexible and easy to use, enabling developers to integrate Google search results into their Python applications with minimal setup.

Installation

To install googlespy, simply use the following pip command:

pip install googlespy

This will download and install the package along with all its dependencies. After installation, you can start using it in your Python scripts.

Usage

Basic Search

To perform a simple Google search, use the search() function with a query string. You can also limit the number of results and apply additional filters.

from googlespy import search

results = search(
    query="Python tutorial",
    limit=10,
    file_type=None,
    keyword=None,
    domain=None
)

for link in results:
    print("result:", link)

This will search Google for "Python tutorial" and display up to 10 results.

Search with File Type Filter

You can filter search results by file type. For example, if you want to find only PDF files related to Python tutorials:

from googlespy import search

results = search(
    query="Python tutorial",
    limit=10,
    file_type="pdf"
)

for link in results:
    print("result:", link)

This will only return results that are PDF files.

Search with Keyword Filter

If you want to narrow your search to results that contain a specific keyword, you can use the keyword parameter:

from googlespy import search

results = search(
    query="Python tutorial",
    limit=10,
    keyword="learn"
)

for link in results:
    print("result:", link)

This will filter the search results to only those that contain the word "learn" in their description.

Search with Domain Filter

To restrict the search results to a specific domain, use the domain parameter. For example, if you want to find Python tutorials only from educational institutions, you can filter by the "edu" domain:

from googlespy import search

results = search(
    query="Python tutorial",
    limit=10,
    domain="edu"
)

for link in results:
    print("result:", link)

This will return search results only from .edu websites.

Search with Language Filter

To filter results based on the language of the content, use the lang parameter. For example, to search for Python tutorials in French:

from googlespy import search

results = search(
    query="Python tutorial",
    limit=10,
    lang="fr"
)

for link in results:
    print("result:", link)

This will return Python tutorial results in French.

Search with Proxy

You can also use a proxy server for your searches by providing a proxy URL. This can be useful if you want to anonymize your searches or access results from a different geographical location:

from googlespy import search

proxy = 'http://199.36.158.100:8080/'

results = search(
    query="proxy test",
    limit=100,
    lang="en",
    proxy=proxy,
    ssl_verify=False
)

for link in results:
    print("result:", link)

This will route the search requests through the specified proxy server.

Search with Interval Between Requests

To avoid triggering rate limits or CAPTCHA challenges, you can specify an interval between search requests. This is especially useful if you need to perform multiple searches:

from googlespy import search

results = search(
    query="Python tutorial",
    limit=10,
    interval=5
)

for link in results:
    print("result:", link)

This will introduce a 5-second delay between each search request.

Advanced Search

For more advanced filtering, you can enable the advanced parameter, which will apply additional filters and return more refined search results:

from googlespy import search

results = search(
    query="Python tutorial",
    limit=10,
    advanced=True
)

for link in results:
    print("result:", link)

This enables advanced filtering for more precise results.

Search with Safe Mode Disabled

Google’s SafeSearch can be disabled to allow more unrestricted search results. To disable SafeSearch, set safe=None:

from googlespy import search

results = search(
    query="Python tutorial",
    limit=10,
    safe=None
)

for link in results:
    print("result:", link)

This will return results without SafeSearch filtering.

Search with Specific Limit

To limit the number of results returned by the search, use the limit parameter. For example, to get only 20 results:

from googlespy import search

results = search(
    query="Python tutorial",
    limit=20
)

for link in results:
    print("result:", link)

This will return exactly 20 search results.

Search for Specific File Type

If you want to filter search results by file type, you can use the file_type parameter. For example, to find only PDF files related to Python tutorials:

from googlespy import search

results = search(
    query="Python tutorial",
    limit=10,
    file_type="pdf"
)

for link in results:
    print("result:", link)

This will return only PDF files.

Search with Multiple Filters

You can apply multiple filters at the same time. For example, to search for Python tutorials that are PDF files, contain the word "learn," and are hosted on .edu domains:

from googlespy import search

results = search(
    query="Python tutorial",
    limit=10,
    file_type="pdf",
    keyword="learn",
    domain="edu"
)

for link in results:
    print("result:", link)

This allows for highly specific searches with multiple criteria.

Search with Skip Invalid Links

If you want to skip invalid links in the search results, set the skip_invalid parameter to True:

from googlespy import search

results = search(
    query="Python tutorial",
    limit=10,
    skip_invalid=True
)

for link in results:
    print("result:", link)

This will filter out any invalid links that may appear in the search results.

Full Example

Here’s a full example demonstrating multiple filters applied together:

from googlespy import search

results = search(
    query="Google",
    limit=10,
    file_type="pdf",
    keyword="tutorial",
    domain="com",
    lang="en",
    interval=3,
    proxy="http://199.36.158.100:8080",
    ssl_verify=False,
    advanced=True
)

for link in results:
    print("result:", link)

This example performs a Google search for "Google" with several filters, including file type, keyword, domain, and more.

License

MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

googlespy-1.0.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

googlespy-1.0.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file googlespy-1.0.1.tar.gz.

File metadata

  • Download URL: googlespy-1.0.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.2

File hashes

Hashes for googlespy-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d63520c072ef37afab2a186c7fdcab46c9162849735fee962008c2106314e830
MD5 c6ef3f02a0d13066f3bd75a5dc6f31fc
BLAKE2b-256 df6103595d5943d259d41e7363cd4bf57c8411a91d5b15ee04e9b190df32a4d2

See more details on using hashes here.

File details

Details for the file googlespy-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: googlespy-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.2

File hashes

Hashes for googlespy-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 164b994579cdbd3dddc217ae3d73b8156c7c939e228c6e288173d9ac41c7234f
MD5 76147a3bdb9889bcf0bc73bc7cf52b66
BLAKE2b-256 05fde62610d46d41549805823c451341027d8d4695ac37fc0bee7addabaeb722

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page