首页 > 解决方案 > 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")]')

我不明白为什么这两者之间有区别。提前致谢。

标签: pythonxpathscrapy

解决方案


推荐阅读