python - 抓取物理治疗实践列表并展开所有项目列表
问题描述
在这里,我正在尝试从德国黄页创建物理治疗师列表。实际数量是 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)
解决方案
可能它来自另一个 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
推荐阅读
- c# - 如何修复“每个表只能配置一列'Identity'。在Ef Core和Oracle中调用'ValueGeneratedNever'......
- laravel - Laravel:如何使用模型运行之外的数据创建 groupBy 并使用 where claus
- python - 根据 lambda 函数将 NumPy 整数列表值映射到列表
- vue.js - 无法即时更改过渡组的过渡
- java - 将密钥标识符作为 X509SubjectKeyIdentifier 签名失败的 SOAP XML WS-Security
- django - Django 使用略有不同的模板发送邮件
- encoding - 用于编码“UTF8”的无效字节序列:当我尝试使用 FormData 对象向服务器发布和图像时出现 0x00 响应
- c# - 命名空间“Microsoft”中不存在类型或命名空间名称“AspNetCore”(您是否缺少程序集引用?)
- python - 输入一次而不是多次询问
- build - 编译 grpc 错误 zlib_compress 和 zlib_decompress