首页 > 解决方案 > 抓取物理治疗实践列表并展开所有项目列表

问题描述

在这里,我正在尝试从德国黄页创建物理治疗师列表。实际数量是 90+,这里我得到 52 个,其中 50 个是列表,其中 2 个是不需要的项目。黄色标记是不需要的项目。如何从列表中删除它们并将其全部展开,以便我从该页面获取所有列表。

web_address ='https://www.gelbeseiten.de/Suche/Physiotherapie%20praxis/Rostock'

business_name = soup.find_all('articles', h2 ='data-wipe-name="Title"')
business_name = soup.find_all('h2')
for name in business_name:
   print(name.get_text())
print(business_name)

物理治疗师从业者名单

标签: pythonbeautifulsoup

解决方案


可能它来自另一个 h2 标签,因为您的方法find_all在该标签上,您可以指定attrs并删除这 2 个不需要的项目

import requests
from bs4 import BeautifulSoup
res=requests.get("https://www.gelbeseiten.de/Suche/Physiotherapie%20praxis/Rostock")
soup=BeautifulSoup(res.text,"html.parser")

business_name = soup.find_all('h2',attrs={"data-wipe-name":"Titel"}) 
for name in business_name:
    print(name.get_text()) 


print(len(business_name))

输出:

Göllner Sabine Krankengymnastik & Physiotherapie
Friemel Physiotherapie Inh. B. Neumann Krankengymnastik & Physiotherapie
Nehrenberg Dorothee Physiotherapie
...
50

推荐阅读