1

I'm trying to do a google search using python, it's basically web scraping. I'm searching using a specific phrase, and I'm expecting a detailed output. I also would like to avoid using other web scraping modules, such as bs4 (BeautifulSoup4) or urllib.

I'm using the googlesearch-python module, but it's not working as expected:

from googlesearch import search

search("my search", advanced=True)

but I get this output:

<generator object search at 0x000001B4F198F290>

and when I try using the print() function:

from googlesearch import search

print(search("my search", advanced=True))

it still returns:

<generator object search at 0x000001B4F198F290>.

(Advanced is an argument that makes the search more detailed and return more information.)

Sometimes, I also get no output at all (meaning that the program ends immediately, as if there were 0 lines of code in it), and other times I get the generator object output. Is there a way to return a clean, detailed output with the googlesearch-python module? (This question is a follow up to my previous question about the googlesearch module: "Python google search 'advanced' argument unexpected")

2

1 Answer 1

3

You are getting a Python generator. Try to convert it into a List to see the actual results.

from googlesearch import search

# Convert the generator to a list and print the results
results = list(search("my search", num=10, advanced=True))
print(results)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.