python - Python Scrapy XPATH 链选择器不同的结果
问题描述
问题: 我正在尝试使用 xpath 选择器链来选择具有scrapy 的某些元素,但我发现我的链的结果与在一个选择器中执行它的结果不同,我想了解为什么会发生这种情况。
scrapy shell https://www.gelbe-liste.de/produkte/Mykofungin-3-200-mg-Vaginaltabletten_826512
当我在下面的一个选择器中执行时,我什么都没有(这就是我想要的,我只想要 praeparat 部分下的 fachinformatio):
response.xpath("//div[@id='praeparat']//a[contains(@href, 'fachinformatio')]")
当我在两个选择器中执行时,我得到的东西不是来自准备工作,而是整个 html:
content = response.css("div.content")
preparation = content.css("div[id='praeparat']")
preparation.xpath('//a[contains(@href, "fachinformation")]')
我不明白为什么这两者之间有区别。提前致谢。
解决方案
推荐阅读
- python-3.x - 使用 setuptools(setup.py) 在主模块之外添加文件夹和子文件夹
- javascript - 加载时我需要显示和获取图像大小
- elasticsearch - Elasticsearch,集群性能比单主机服务器差吗?
- javafx - 类 Circle 中的构造函数 Circle 不能应用于给定类型
- r - 如何使用 R 运行双循环
- amazon-web-services - 如何在 AWS SQS 中查看特定日期收到的消息?(或者今天最后一次收到)
- amazon-web-services - 移动应用程序中的 AWS AccessKeyId 和 SecretKey
- ruby-on-rails - 如何检查值是否在 CanCanCan 条件散列的数组中
- java - 列出一个类的所有字段,如果它们匹配所需的类型,则将它们放在一个列表中
- sql - SQL 一个字段计数其他字段的聚合