Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中使用xpath提取xml中的特定节点_Python_Xml_Xpath_Amazon Web Services - Fatal编程技术网

如何在python中使用xpath提取xml中的特定节点

如何在python中使用xpath提取xml中的特定节点,python,xml,xpath,amazon-web-services,Python,Xml,Xpath,Amazon Web Services,我正在使用AmazonAPI进行项目查找 它返回这种类型的xml对象。我想知道如何使用xpath提取的超链接 但这张单子是空的 编辑: 当我执行[result.xpath('/*')中x的x.tag]时,我得到了这个结果: ['{http://webservices.amazon.com/AWSECommerceService/2011-08-01}ItemLookupResponse','{http://webservices.amazon.com/AWSECommerceService/20

我正在使用AmazonAPI进行项目查找

它返回这种类型的
xml
对象。我想知道如何使用
xpath
提取
超链接

但这张单子是空的

编辑:


当我执行
[result.xpath('/*')中x的x.tag]
时,我得到了这个结果:

['{http://webservices.amazon.com/AWSECommerceService/2011-08-01}ItemLookupResponse','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}操作请求','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}HTTPHeaders','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}标题“,”{http://webservices.amazon.com/AWSECommerceService/2011-08-01}请求ID','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}参数','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}论点','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}论点','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}论点','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}论点','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}论点','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}论点','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}论点','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}论点','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}论点','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}论点','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}论点','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}请求处理时间','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}项目','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}请求','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}是有效的','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}ItemLookupRequest','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}IdType','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}ItemId','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}响应组','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}变量页','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}包括查看摘要','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}截断视图卫星','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}项目','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}阿辛','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}CustomerReviews','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}IFrameURL','{http://webservices.amazon.com/AWSECommerceService/2011-08-01}HasReviews']

编辑2:
我现在以
http://www.amazon.com/reviews/iframe?akid=HIDDEN&alinkCode=xm2&asin=B00062B6QY&atag=HIDDEN&exp=2014-01-28T07%3A55%3A45Z&summary=0&truncate=256&v=2&sig=HIDDED%3D

忽略命名空间时进行查询

>>> result.xpath('//*[local-name()="IFrameURL"]/text()')[0].strip()
'http://www.amazon.com/reviews/iframe?akid=[AWS Access Key ID]&asin=0316067938&exp=2011-08-01T17%3A54%3A07Z&linkCode=xm2&summary=0&tag=ws&truncate=256&v=2&sig=[Signature]'

我得到
索引器:列表索引超出范围
结果。xpath('//iframeurl/text()')
正在返回空列表
[x.tag for x in result.xpath('//*')]
若要查看其中的内容,我已将我在上面的编辑中得到的内容包括在内。我确实看到了
iframeurl
谢谢。这很有帮助,但你能解释一下你在上面做了什么吗?我已经粘贴了我得到的文本。现在我必须解析它以获得评论。
result = api.item_lookup('0316067938', ResponseGroup='Reviews',
     TruncateReviewsAt=256, IncludeReviewsSummary=False)
print result.xpath('//IFrameURL')
>>> result.xpath('//*[local-name()="IFrameURL"]/text()')[0].strip()
'http://www.amazon.com/reviews/iframe?akid=[AWS Access Key ID]&asin=0316067938&exp=2011-08-01T17%3A54%3A07Z&linkCode=xm2&summary=0&tag=ws&truncate=256&v=2&sig=[Signature]'