python3.x - python lxml cannot find the text of sub-tags whose first tag has a link and does not have a content tag?
PHP中文网
PHP中文网 2017-05-24 11:35:06
0
1
583

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中文网

认证0级讲师

reply all(1)
仅有的幸福

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!