csv NoneType不可调用,BeautifulSoup

omjgkv6w  于 2023-07-31  发布在  其他
关注(0)|答案(1)|浏览(97)

下面是我的代码

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

我希望给予一个数据库,#dataframe在CSV文件中的网站和位置

tjjdgumg

tjjdgumg1#

在第10行,方法.findall()应该是.find_all()

相关问题