我试图使用lxml返回标记内的文本<ImageSet><LargeImage><URL>this text</URL></LargeImage></ImageSet>
我的代码只对每个标记下的文本返回None。在
这是我的代码:
# I am trying to get the URL text using lxml
for attr_list in tree.iterfind(".//"+settings.AMAZON_NS+"ImageSet"):
for image_list in tree.find(".//"+settings.AMAZON_NS+"LargeImage"):
print(etree.tostring(image_list))
print(image_list.findtext(".//"+settings.AMAZON_NS+"URL")) # This is only printing None.
以下是代码输出:
^{pr2}$第11、17、23行等。。。应该显示一个URL而不是一个。在
编辑1:让我试着澄清我的上述问题…
这是我使用的代码:
for item in tree.iterfind(".//"+settings.AMAZON_NS+"ImageSet"):
for image_set in item.find(".//"+settings.AMAZON_NS+"LargeImage"):
print(etree.tostring(image_set))
这是我得到的输出: http://dpaste.com/289187/
如何具体获取URL标记中的内容?在
我试过以下几点(虽然都不管用,但也许你们能从失败的尝试中看出我要做什么的大致思路):
for item in tree.iterfind(".//"+settings.AMAZON_NS+"ImageSet"):
for image_set in item.find(".//"+settings.AMAZON_NS+"LargeImage"):
for image_url_set in image_set.find(".//"+settings.AMAZON_NS+"URL"):
print(etree.tostring(image_url_set))
我得到的错误是:
在图像中设置的图像_设置。查找(".//"+设置.亚马逊+“网址”): TypeError:“NoneType”对象不可读取
for item in tree.iterfind(".//"+settings.AMAZON_NS+"ImageSet"):
for image_set in item.find(".//"+settings.AMAZON_NS+"LargeImage"):
for image_link in image_set.iter(".//"+settings.AMAZON_NS+"URL"):
print(image_link.text)
连指纹都没有。在
尝试更换
与正义
^{pr2}$其中
body
是xml文本。在输出
^{pr2}$相关问题 更多 >
编程相关推荐