python - lxml-html 解析非常深的标签级python
问题描述
我需要使用 lxml python 模块从 html 标签获取图像源。 基本上我请求的网址是 - https://aeroparque.shopdutyfree.com/en/catalogsearch/result/?q=chocolate ,我只需要使用 lxml 获取任何产品图片的图像源。我的代码:
import requests
import lxml.html
.xpath('//a[@class="product photo product-item-photo"]/img[@class="product-image-photo"]/@src/text()')
for i in image:
print(i)
解决方案
/@src
返回src
属性的值,这是一个简单的字符串。添加/text()
不会返回任何内容,因为text()
从元素中提取文本,而不是属性。
推荐阅读
- excel - 是否可以制作一个可以搜索谷歌电子表格并返回特定单元格值的电报机器人?
- javascript - 无法让数据表编辑器初始化
- scala - 具有无标签最终样式的 Kleisli 依赖项
- sharepoint - 如何在 PowerApps 中解析 JSON?
- python - 达到阈值后,累积熊猫列“重置”
- docker - 在托管 Angular 应用程序的 nginx docker 容器上配置 HTTPS
- angular - 添加多个子窗体
- c# - 在此处添加 try-catch 构造以捕获“ArgumentNullException”
- python - 当我们释放对 kivy 开关项目的点击时如何触发一个事件?
- javascript - MTN MOMO API CreateAPI 用户 - 401 访问被拒绝