XPath 页脚或正文 - 仅在存在时使用节点
XPath footer or body - Use node only if exists
我正在尝试为 scrapy CrawlSpider restrict_xpaths LinkExtractor 构建一个 Xpath 条件,它会尝试查找页脚中的所有链接,如果页脚不存在,则查找正文中的所有链接。如果两者都存在,则只查找页脚中的链接。
我现在只有这个
restrict_xpaths = ["//footer","//head"]
好的答案:
restrict_xpaths = ["//footer//a | //a[not(//footer)]"]
更一般地说:
narrow[global contition] | wider[not(global condition)]
我正在尝试为 scrapy CrawlSpider restrict_xpaths LinkExtractor 构建一个 Xpath 条件,它会尝试查找页脚中的所有链接,如果页脚不存在,则查找正文中的所有链接。如果两者都存在,则只查找页脚中的链接。
我现在只有这个
restrict_xpaths = ["//footer","//head"]
好的答案:
restrict_xpaths = ["//footer//a | //a[not(//footer)]"]
更一般地说:
narrow[global contition] | wider[not(global condition)]