Issue
#Below is my code
import requests
from bs4 import BeautifulSoup
import pandas as pd
response = requests.get('https://www.google.com/maps/search/dance+studio')
soup = BeautifulSoup(response.content, 'html.parser')
results = soup.findall('div','section-result-content')
emails = []
locations = []
websites = []
social_media = []
for result in results:
location_elem = result.find('span', 'section-result-location')
location = location_elem.text.strip() if location_elem else ""
locations.append(location)
website_elem = result.find('span', 'section-result-action section-result-action-wide')
website = website_elem.a['href'] if website_elem else ""
websites.append(website)
data = {'Email': emails, 'Location': locations, 'Website': websites, 'Social Media': social_media}
df = pd.DataFrame(data)
df.to_csv('dance_studio.csv', index=False)``
To explain what happening, I using google map and trying to find website and location of dance studio, When I run it give
Traceback (most recent call last): File " ", line 10, in <module> results = soup.findall('div','section-result-content') TypeError: 'NoneType' object is not callable
#What I am expecting to give a database, #dataframe in CSV file of their Website and Location
Solution
On line 10, the method .findall()
should be .find_all()
Answered By - Taige Wang
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.