下面是我的代码
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)``
字符串
为了解释发生了什么,我使用谷歌Map,并试图找到网站和舞蹈工作室的位置,当我运行它给予Traceback (most recent call last): File " ", line 10, in <module> results = soup.findall('div','section-result-content') TypeError: 'NoneType' object is not callable
1条答案
按热度按时间tjjdgumg1#
在第10行,方法
.findall()
应该是.find_all()