0

I am trying to build a Xpath condition for scrapy CrawlSpider restrict_xpaths LinkExtractor which tries to go for all links in the footer, if footer does not exists, go for all the links in the body. If both exists, only go for links in the footer.

All I have right now is this

 restrict_xpaths = ["//footer","//head"]
IndiaSke
  • 348
  • 1
  • 2
  • 10
  • Does this answer your question? [How to check if an element exists in the XML using XPath?](https://stackoverflow.com/questions/5689966/how-to-check-if-an-element-exists-in-the-xml-using-xpath) – baduker Nov 02 '21 at 13:02
  • What is the //head doing in your array? – Siebe Jongebloed Nov 02 '21 at 15:46

1 Answers1

1

Good answer :

restrict_xpaths = ["//footer//a | //a[not(//footer)]"]

More generally :

narrow[global contition] | wider[not(global condition)]
IndiaSke
  • 348
  • 1
  • 2
  • 10