Home > database >  xpath for no tag elements
xpath for no tag elements

Time:10-28

<span >abc</span>"efg"

How can I get the value of efg using XPath? I am able to get abc by //span[@]

CodePudding user response:

You can use the following-sibling::text() predicate in your xpath expression.

Here is an example:

from lxml import html

hstr = '<div><span >abc</span>"efg"</div>'

h = html.fromstring(hstr)
h.xpath('//span[@]/following-sibling::text()')
# returns:
['"efg"']
  • Related