第一个situation:tag内有link
from lxml import etree
node = etree.fromstring('<a xml = 'www.www.com'><c>bum</c></a>')
print node.findtext('c',default = 'what happened?')
第二个situation:所求text所在tag上一级tag无content
from lxml import etree
node = etree.fromstring('<a><b><c>bum</c></b></a>')
print node.findtext('c', default = 'what happened?')
以上两个situation所返回的结果都是‘None’
成功的situation
from lxml import etree
node = etree.fromstring('<a><c>bum</c></a>')
print node.findtext('c')
想问一下这两个问题应该怎么解决?
给你推荐pyquery,个人认为更好用