XPATH: a specific word in a paragraph

I am trying to figure out how to get the exact xpath for example. third word in a paragraph:

eg:.

<p>Here is some text</p>

      

then if I want the third word ("some") I cannot figure out how to do it using xpath. However, the trick here is not to get an exact match for the word β€œsome”, but to get the third word (whatever it is).

I've tried with this: ../ p [3] but doesn't help. I am using python and scrapy framework.

Hopefully someone can point me in the right direction.

Thank.

+3


source to share


1 answer


if you are using scrapy as this question was tagged, consider using scrapy .re()

, ie:



>>> response.xpath('//p/text()').re('\w+')[2]
u'some'

      

+2


source







All Articles