-1

我有一些非常“深”的 XML(见底部),并且正在努力使用 minidom 或 elementtree 来获得我需要的值 - 知道获得粗体值 (VALUE_TO_GET) 的最简单方法是什么会有不同数量的LowestOfferListing标签?我基本上需要为每个获取LandedPrice/的第一个实例,并且找不到这样做的简单(ish)方法!AmountSKUIdentifier

<?xml version="1.0" ?>
<GetLowestOfferListingsForSKUResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
  <GetLowestOfferListingsForSKUResult SellerSKU="X" status="Success">
    <AllOfferListingsConsidered>true</AllOfferListingsConsidered>
    <Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" 
             xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
      <Identifiers>
        <MarketplaceASIN>
          <MarketplaceId>X</MarketplaceId>
          <ASIN>X</ASIN>
        </MarketplaceASIN>
        <SKUIdentifier>
          <MarketplaceId>X</MarketplaceId>
          <SellerId>X</SellerId>
          <SellerSKU>**VALUE_TO_GET**</SellerSKU>
        </SKUIdentifier>
      </Identifiers>
      <LowestOfferListings>
        <LowestOfferListing>
          <Qualifiers>
            <ItemCondition>New</ItemCondition>
            <ItemSubcondition>New</ItemSubcondition>
            <FulfillmentChannel>Amazon</FulfillmentChannel>
            <ShipsDomestically>True</ShipsDomestically>
            <ShippingTime>
              <Max>X</Max>
            </ShippingTime>
            <SellerPositiveFeedbackRating>X</SellerPositiveFeedbackRating>
          </Qualifiers>
          <NumberOfOfferListingsConsidered>3</NumberOfOfferListingsConsidered>
          <SellerFeedbackCount>X</SellerFeedbackCount>
          <Price>
            <LandedPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>**VALUE_TO_GET**</Amount>
            </LandedPrice>
            <ListingPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </ListingPrice>
            <Shipping>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </Shipping>
          </Price>
          <MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice>
        </LowestOfferListing>
        <LowestOfferListing>
          <Qualifiers>
            <ItemCondition>X</ItemCondition>
            <ItemSubcondition>X</ItemSubcondition>
            <FulfillmentChannel>Merchant</FulfillmentChannel>
            <ShipsDomestically>X</ShipsDomestically>
            <ShippingTime>
              <Max>X</Max>
            </ShippingTime>
            <SellerPositiveFeedbackRating>X</SellerPositiveFeedbackRating>
          </Qualifiers>
          <NumberOfOfferListingsConsidered>X</NumberOfOfferListingsConsidered>
          <SellerFeedbackCount>X</SellerFeedbackCount>
          <Price>
            <LandedPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </LandedPrice>
            <ListingPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </ListingPrice>
            <Shipping>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </Shipping>
          </Price>
          <MultipleOffersAtLowestPrice>X</MultipleOffersAtLowestPrice>
        </LowestOfferListing>
        <LowestOfferListing>
          <Qualifiers>
            <ItemCondition>X</ItemCondition>
            <ItemSubcondition>X</ItemSubcondition>
            <FulfillmentChannel>X</FulfillmentChannel>
            <ShipsDomestically>X</ShipsDomestically>
            <ShippingTime>
              <Max>X</Max>
            </ShippingTime>
            <SellerPositiveFeedbackRating>X</SellerPositiveFeedbackRating>
          </Qualifiers>
          <NumberOfOfferListingsConsidered>X</NumberOfOfferListingsConsidered>
          <SellerFeedbackCount>X</SellerFeedbackCount>
          <Price>
            <LandedPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </LandedPrice>
            <ListingPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </ListingPrice>
            <Shipping>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </Shipping>
          </Price>
          <MultipleOffersAtLowestPrice>X</MultipleOffersAtLowestPrice>
        </LowestOfferListing>
        <LowestOfferListing>
          <Qualifiers>
            <ItemCondition>X</ItemCondition>
            <ItemSubcondition>X</ItemSubcondition>
            <FulfillmentChannel>X</FulfillmentChannel>
            <ShipsDomestically>X</ShipsDomestically>
            <ShippingTime>
              <Max>X</Max>
            </ShippingTime>
            <SellerPositiveFeedbackRating>X</SellerPositiveFeedbackRating>
          </Qualifiers>
          <NumberOfOfferListingsConsidered>X</NumberOfOfferListingsConsidered>
          <SellerFeedbackCount>X</SellerFeedbackCount>
          <Price>
            <LandedPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </LandedPrice>
            <ListingPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </ListingPrice>
            <Shipping>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </Shipping>
          </Price>
          <MultipleOffersAtLowestPrice>X</MultipleOffersAtLowestPrice>
        </LowestOfferListing>
        <LowestOfferListing>
          <Qualifiers>
            <ItemCondition>X</ItemCondition>
            <ItemSubcondition>X</ItemSubcondition>
            <FulfillmentChannel>X</FulfillmentChannel>
            <ShipsDomestically>X</ShipsDomestically>
            <ShippingTime>
              <Max>X</Max>
            </ShippingTime>
            <SellerPositiveFeedbackRating>X</SellerPositiveFeedbackRating>
          </Qualifiers>
          <NumberOfOfferListingsConsidered>X</NumberOfOfferListingsConsidered>
          <SellerFeedbackCount>X</SellerFeedbackCount>
          <Price>
            <LandedPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </LandedPrice>
            <ListingPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </ListingPrice>
            <Shipping>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </Shipping>
          </Price>
          <MultipleOffersAtLowestPrice>X</MultipleOffersAtLowestPrice>
        </LowestOfferListing>
      </LowestOfferListings>
    </Product>
  </GetLowestOfferListingsForSKUResult>
  <GetLowestOfferListingsForSKUResult SellerSKU="X" status="X">
    <AllOfferListingsConsidered>X</AllOfferListingsConsidered>
    <Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"
             xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
      <Identifiers>
        <MarketplaceASIN>
          <MarketplaceId>X</MarketplaceId>
          <ASIN>X</ASIN>
        </MarketplaceASIN>
        <SKUIdentifier>
          <MarketplaceId>X</MarketplaceId>
          <SellerId>X</SellerId>
          <SellerSKU>**VALUE_TO_GET**</SellerSKU>
        </SKUIdentifier>
      </Identifiers>
      <LowestOfferListings>
        <LowestOfferListing>
          <Qualifiers>
            <ItemCondition>X</ItemCondition>
            <ItemSubcondition>X</ItemSubcondition>
            <FulfillmentChannel>X</FulfillmentChannel>
            <ShipsDomestically>X</ShipsDomestically>
            <ShippingTime>
              <Max>X</Max>
            </ShippingTime>
            <SellerPositiveFeedbackRating>X</SellerPositiveFeedbackRating>
          </Qualifiers>
          <NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered>
          <SellerFeedbackCount>X</SellerFeedbackCount>
          <Price>
            <LandedPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>**VALUE_TO_GET**</Amount>
            </LandedPrice>
            <ListingPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </ListingPrice>
            <Shipping>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </Shipping>
          </Price>
          <MultipleOffersAtLowestPrice>X</MultipleOffersAtLowestPrice>
        </LowestOfferListing>
        <LowestOfferListing>
          <Qualifiers>
            <ItemCondition>X</ItemCondition>
            <ItemSubcondition>X</ItemSubcondition>
            <FulfillmentChannel>X</FulfillmentChannel>
            <ShipsDomestically>X</ShipsDomestically>
            <ShippingTime>
              <Max>X</Max>
            </ShippingTime>
            <SellerPositiveFeedbackRating>X</SellerPositiveFeedbackRating>
          </Qualifiers>
          <NumberOfOfferListingsConsidered>8</NumberOfOfferListingsConsidered>
          <SellerFeedbackCount>X</SellerFeedbackCount>
          <Price>
            <LandedPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </LandedPrice>
            <ListingPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </ListingPrice>
            <Shipping>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </Shipping>
          </Price>
          <MultipleOffersAtLowestPrice>X</MultipleOffersAtLowestPrice>
        </LowestOfferListing>
        <LowestOfferListing>
          <Qualifiers>
            <ItemCondition>X</ItemCondition>
            <ItemSubcondition>X</ItemSubcondition>
            <FulfillmentChannel>Merchant</FulfillmentChannel>
            <ShipsDomestically>X</ShipsDomestically>
            <ShippingTime>
              <Max>X</Max>
            </ShippingTime>
            <SellerPositiveFeedbackRating>X</SellerPositiveFeedbackRating>
          </Qualifiers>
          <NumberOfOfferListingsConsidered>4</NumberOfOfferListingsConsidered>
          <SellerFeedbackCount>X</SellerFeedbackCount>
          <Price>
            <LandedPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </LandedPrice>
            <ListingPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </ListingPrice>
            <Shipping>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </Shipping>
          </Price>
          <MultipleOffersAtLowestPrice>X</MultipleOffersAtLowestPrice>
        </LowestOfferListing>
        <LowestOfferListing>
          <Qualifiers>
            <ItemCondition>X</ItemCondition>
            <ItemSubcondition>X</ItemSubcondition>
            <FulfillmentChannel>X</FulfillmentChannel>
            <ShipsDomestically>X</ShipsDomestically>
            <ShippingTime>
              <Max>X</Max>
            </ShippingTime>
            <SellerPositiveFeedbackRating>X</SellerPositiveFeedbackRating>
          </Qualifiers>
          <NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered>
          <SellerFeedbackCount>X</SellerFeedbackCount>
          <Price>
            <LandedPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </LandedPrice>
            <ListingPrice>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </ListingPrice>
            <Shipping>
              <CurrencyCode>X</CurrencyCode>
              <Amount>X</Amount>
            </Shipping>
          </Price>
          <MultipleOffersAtLowestPrice>X</MultipleOffersAtLowestPrice>
        </LowestOfferListing>
      </LowestOfferListings>
    </Product>
  </GetLowestOfferListingsForSKUResult>
  <ResponseMetadata>
    <RequestId>X</RequestId>
  </ResponseMetadata>
</GetLowestOfferListingsForSKUResponse>
4

1 回答 1

1

首先,您的 xml 似乎无效,因为它给出了一个错误elemntree,所以我尝试了它lxml.html,虽然它更健壮,xpath但仍然保持不变。

import lxml.html as lh
doc=lh.fromstring(xml)
doc.xpath('//sellersku/text()|//product/descendant::amount[1]/text()')

输出:

['**VALUE_TO_GET**',
 '**VALUE_TO_GET**',
 '**VALUE_TO_GET**',
 '**VALUE_TO_GET**']
于 2013-01-14T19:44:56.963 回答