python - 使用 xpath 获取图像
问题描述
我一直在尝试从该网站的滑动条获取图像:https ://propertyfox.co.za/property/pf10434/我似乎无法访问该课程,因此我决定检查页面源。但是,我仍然在挣扎,不知道我做错了什么
这就是我现在拥有的代码的样子,但我总是得到一个空数组:
images = response.xpath('//*[@class="pagination-item"]//*[has-class("total-slide")]/span/text()').extract()
有什么建议么?谢谢!
解决方案
在页面源中,您可以看到图像链接存储在id="galleryatts"
. 以下 xpath 获取图像:
images = response.xpath('//*[@id="galleryatts"]/@data-allimg').extract_first()
这样你就可以得到一个字符串中的所有图像,用分号分隔。要将图像作为列表获取,您只需执行以下操作:
image_urls = images.split(';')
推荐阅读
- websocket - 如何使用 Absinthe (Elixir) 和 Urql 进行 graphql 订阅?
- xml - 读取 XML 并存储在变量、ASMX、VB.NET 中
- c# - Selenium c# System.InvalidOperationException: '会话未创建'
- flutter - 带有放大和缩小选项的颤振扫描二维码
- python - 在方法中将字符串传递给 eval
- python - 使用 Pandas 访问 Python 中的列
- notifications - FHIR 管理通知
- visual-studio - Azure DevOps Server 升级期间无法删除弹性搜索服务
- python - 使用正则表达式逐行解析没有分隔符的文本
- python - 如何使用 URL 从数据库中检索数据