__parse_place function error
Closed this issue · 2 comments
When running the scraper.py file, print(scraper.get_account(url)) in line 41 and 42 is never executed. I commented out the if statement and found an error under the __parse_place function in line 164 and 165.
Error:
File "googlemaps.py", line 165, in __parse_place
place['overall_rating'] = float(response.find('div', class_='gm2-display-2').text.replace(',', '.')) AttributeError: 'NoneType' object has no attribute 'text'
Tried using the required beautifulsoup, selenium version and tried different versions of chromedriver. That did not solve the issue. What could be the problem?
The error is due to no text found in element 'div' with class 'gm2-display-2'. Did you verify if the link you scrape which causes this error actually has a RATING on the page.
If you are using over a lot of urls and do not care about a few of them, then you can catch the exception
and continue as follows:
def __parse_place(self, response):
try:
place = {}
place['overall_rating'] = float(response.find('div', class_='gm2-display-2').text.replace(',', '.'))
place['n_reviews'] = int(response.find('div', class_='gm2-caption').text.replace('.', '').replace(',','').split(' ')[0])
except Exception as e:
# print something or pass
place['overall_rating'] = 'NOT_FOUND'
return place
Hi,
latest commit to master fixed this issue: now I added a try-catch block for each field.
Bye,
Mattia