abenassi / Google-Search-API

Python based api for searching google web, images, calc, and currency conversion.
558 stars 217 forks source link

FIY another easy "fix" to empty list issue #101

Open GordonRamsay-689 opened 2 weeks ago

GordonRamsay-689 commented 2 weeks ago

First of all, make sure you have the correct version of bs4 installed.

You can run the following commands at your own risk if you want to completely uninstall old versions and install bs4 for python3:

$ pip uninstall beautifulsoup4
$ pip3 uninstall beautifulsoup4   
$ pip uninstall BeautifulSoup
$ pip3 uninstall BeautifulSoup
$ pip3 install beautifulsoup4

Now, this did NOT fix the empty list issue for me, but this is important first step in case you have accidentally installed the wrong version. The reason was because the description would always be None, and thus the check in modules/standard_search.py would always be true, and thus not append to results.

_in 'modules/standardsearch.py' on line 96:

if void is True:
    if res.description is None:
        continue

This check can prevent empty results being added, but as soon as the description parsing function is no longer current this will mess everything up, leaving you with an empty list.

I replaced it with a simpler check (which you should really expand upon if you want to avoid unpopulated responses):

if res is None:
    continue
if res.description is None: # Optional
    res.description = "No description" 

Obviously this does not fix the function to get the description, but it does make sure you can get links, title etc.