【发布时间】:2014-02-17 18:05:28
【问题描述】:
我正在使用 python-amazon product module 在 amazon api 中查找项目。
它返回这种类型的xml 对象。我想知道如何使用xpath提取hyperlink的<IFrameURL>。
<ItemLookupResponse>
<Items>
<Item>
<ASIN>0316067938</ASIN>
<CustomerReviews>
<IFrameURL>
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]
</IFrameURL>
</CustomerReviews>
</Item>
</Items>
</ItemLookupResponse>
我试过这个: 但它不起作用:
result = api.item_lookup('0316067938', ResponseGroup='Reviews',
TruncateReviewsAt=256, IncludeReviewsSummary=False)
print result.xpath('//IFrameURL')
但这给出了空列表
编辑:
当我做[x.tag for x in result.xpath('//*')]时我得到了这个:
['{http://webservices.amazon.com/AWSECommerceService/2011-08-01}ItemLookupResponse', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}OperationRequest', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}HTTPHeaders', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Header', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}RequestId', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Arguments', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Argument', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Argument', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Argument', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Argument', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Argument', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Argument', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Argument', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Argument', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Argument', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Argument', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Argument', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}RequestProcessingTime', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Items', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Request', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}IsValid', '{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}ResponseGroup', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}VariationPage', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}IncludeReviewsSummary', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}TruncateReviewsAt', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}Item', '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}ASIN', '{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=HIDDEN%3D
【问题讨论】:
标签: python xml xpath amazon-web-services