【发布时间】:2020-07-22 22:29:48
【问题描述】:
我需要从这个网站中提取link 商店所在城市的名称。我创建了这段代码:
def get_page_data(number):
print('number:', number)
url = 'https://www.biedronka.pl/pl/sklepy/lista,lat,52.25,lng,21,page,'.format(number)
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
container = soup.find(class_='s-content shop-list-page')
items = container.find_all(class_='shopListElement')
dane = []
for item in items:
miasto = item.find(class_='h4').get_text(strip=True)
adres = item.find(class_='shopFullAddress').get_text(strip=True)
dane.append([adres])
return dane
wszystkie_dane = []
for number in range(1, 2):
dane_na_stronie = get_page_data(number)
wszystkie_dane.extend(dane_na_stronie)
dane = pd.DataFrame(wszystkie_dane, columns=['miasto','adres'])
dane.to_csv('biedronki_lista.csv', index=False)
问题出现在:
miasto = item.find(class_='h4').get_text(strip=True)
AttributeError: 'NoneType' object has no attribute 'get_text'
任何想法如何从该网站提取城市名称(在 h4 中)?
【问题讨论】:
标签: python web-scraping beautifulsoup attributeerror