2
div class="ydpbfddd73dsignature" >......

How do I use xpath to get whatever text comes after this tag?

I tried doing this

nokogiri_html=Nokogiri::HTML html
nokogiri_html.xpath('//div[@class="/.*signature/"]')

But it doesn't work.

Sebastián Palma
  • 32,692
  • 6
  • 40
  • 59

1 Answers1

0

You can apply below XPath:

//div[substring(@class, string-length(@class) - 8)="signature"]

which means return div node which has "signature" as last 9 characters of class name

Andersson
  • 51,635
  • 17
  • 77
  • 129
  • Worked ! Thanks. Can you specify why its -8 and not -9? what does the 8 specify? index from 0 to 8? – anonymous1997 Feb 05 '18 at 16:27
  • Because we should get the index of character from which to start counting. String length of class name is `20`, the index of `s` is `12`, so to get `8` we should do `20 - 12 = 8`. I hope it's clear. Let me know if you have questions – Andersson Feb 05 '18 at 19:15
  • if i want to add a condition where i want to exclude the conditions when class=".......outlooksignature"? i dont want my xpath function to pick up this case alone. – anonymous1997 Feb 09 '18 at 12:15
  • `//div[substring(@class, string-length(@class) - 8)="signature" and not(contains(@class, "outlooksignature"))]` – Andersson Feb 09 '18 at 12:17