-1

The following line of code is used to search for lines of source code that contains the text "#":

XPATH_RANK = '//span[contains(text(),"#")]//text()'

How can I modify this particular line of code to IGNORE certain text?

Please keep in mind that I know next to nothing about Python, and am only learning as I go along with this project for work.

Thanks in advance.

1 Answers1

2

'//span[not(contains(text(),"#"))]//text()'

This question is a duplicate of How to use not contains() in xpath? but here's your use.

Jason Stein
  • 714
  • 3
  • 10
  • Thank you. How can I use this to use certain text but ignore others? For example, what I want to do is have this line use text that contains "#" but ignore text that contains the string "#1 Best Seller". This is what I have right now: `'//span[contains(text(),"#") and not(contains(text(),"#1 Best Seller"))]//text'` Is this correct? If it is, it's not doing what I want it to. – derek00101110 Jun 27 '17 at 18:03
  • you can use multiple square bracket operations. so: `//span[contains(text(),"#")][not(contains(text,"#1 Best Seller"))]` – Jason Stein Jun 27 '17 at 18:18
  • If you are new to building XPATHs, consider sandboxing here: https://www.freeformatter.com/xpath-tester.html#ad-output . Much like regexes, practice and experience help a lot, and using a sandbox is faster than running code every time. Plus this one gives hints. – Jason Stein Jun 27 '17 at 18:20