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

[Programming question]: Searching google #193

Open
haesleinhuepf opened this issue Dec 30, 2024 · 1 comment
Open

[Programming question]: Searching google #193

haesleinhuepf opened this issue Dec 30, 2024 · 1 comment

Comments

@haesleinhuepf
Copy link
Owner

I would like to program a Python function with the signature search_goole(search_term:str)->str.

git-bob comment on how to do this

Copy link
Contributor

This message was generated by git-bob (version: 0.17.0, model: claude-3-5-sonnet-20241022, log), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

Hey there! For searching Google using Python, I recommend using the googlesearch-python library. Here's a simple notebook showing how to do it:

# Install the library first
!pip install googlesearch-python

from googlesearch import search

def search_google(search_term: str) -> str:
    """
    Search Google and return first result
    """
    try:
        # Get first result from Google search
        return next(search(search_term, num_results=1))
    except StopIteration:
        return "No results found"
    except Exception as e:
        return f"Error occurred: {str(e)}"

# Example usage
result = search_google("python programming")
print(result)

Please note that excessive automated queries might get your IP temporarily blocked by Google. For production use, consider using Google's official Custom Search API instead.

Let me know if you need any clarification! 👋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant