Reputation: 91
Here is my code, it was working properly before I was not getting an error while using it. I don't understand how it happened even though I didn't change with it. :
results = []
for query in my_list:
results.append(search(query, tld="com", num=1, stop=1, pause=2))
Error:
results.append(search(query, tld="com", num=1, stop=1, pause=2))
TypeError: search() got an unexpected keyword argument 'tld'
Upvotes: 4
Views: 10913
Reputation: 1
I had the same issue but got a way around it The issue I faced was that I imported the 'search' function outside my 'def search()' function as below
from googlesearch import search
def search(query):
for j in search(query, tld="co.in", num=10, stop=10, pause=2):
urls.append(j)
and i got the error you got
So my way around it was to import the googlesearch.search function inside my search function as below
def search(query):
try:
from googlesearch import search
except:
pass
urls = []
for j in search(query, tld="co.in", num=10, stop=10, pause=2):
urls.append(j)
url = str(urls[0])
And that solved it for me let me know if it works for you
Upvotes: 0
Reputation: 21
It is necessary to install the google
library, installing this library stopped producing the error:
pip install google
Upvotes: 1
Reputation: 1749
It is from the google
python package. it is still working of all the versions.
query
: query string that we want to search for.tld
: tld stands for top level domain which means we want to search our result on google.com or google.in or some other domain.lang
: lang stands for language.num
: Number of results we want.start
: First result to retrieve.stop
: Last result to retrieve. Use None to keep searching forever.pause
: Lapse to wait between HTTP requests. Lapse too short may cause Google to block your IP. Keeping significant lapse will make your program slow but its safe and better option.Return
: Generator (iterator) that yields found URLs. If the stop parameter is None the iterator will loop forever.There is one more python package with the module name as googlesearch
Link here
Since it might be installed on your environment, this might be calling this module which does not have these parameters included.
pip install beautifulsoup4
and pip install google
pip install googlesearch-python
python packageUpvotes: 10