Python GoogleSearch module error : "TypeError: search() got an unexpected keyword argument 'tld' "

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'

Solution 1:

It is from the google python package. it is still working of all the versions.

version parameters :

  • 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.

Here is your real problem:

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.

The BlockBuster Solution is: (tested these both packages on local)

  • Delete your Python Environment
  • Create a new one
  • install pip install beautifulsoup4 and pip install google
  • Now use your code which will work like charm.
  • Never install the pip install googlesearch-python python package