Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__parse_place function error #9

Closed
ghost opened this issue Aug 19, 2020 · 2 comments
Closed

__parse_place function error #9

ghost opened this issue Aug 19, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 19, 2020

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?

@anksng1201
Copy link

anksng1201 commented Aug 21, 2020

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 

@gaspa93
Copy link
Owner

gaspa93 commented Aug 28, 2020

Hi,

latest commit to master fixed this issue: now I added a try-catch block for each field.
Bye,

Mattia

@gaspa93 gaspa93 closed this as completed Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants