Home  >  Q&A  >  body text

python3.x - python lxml cannot find the text of sub-tags whose first tag has a link and does not have a content tag?

The first situation: there is a link in the tag

from lxml import etree 

node = etree.fromstring('<a xml = 'www.www.com'><c>bum</c></a>')

print node.findtext('c',default = 'what happened?')

Second situation: The tag above the requested text has no content

from lxml import etree 

node = etree.fromstring('<a><b><c>bum</c></b></a>')

print node.findtext('c', default = 'what happened?')

The results returned by the above two situations are ‘None’

Successful situation

from lxml import etree 

node = etree.fromstring('<a><c>bum</c></a>')

print node.findtext('c')

I would like to ask how to solve these two problems?

PHP中文网PHP中文网2705 days ago560

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-24 11:37:06

    I recommend pyquery to you, I personally think it is more useful

    reply
    0
  • Cancelreply