eBay 개발자 API 검색 결과에서 가격 정보를 구문 분석하는 간단한 bash 스크립트를 작성하려고 합니다. 다음은 "Detective Comics 700"에 대한 XML 검색 결과의 예입니다.
<findItemsAdvancedResponse xmlns="http://www.ebay.com/marketplace/search/v1/services">
<ack>Success</ack>
<version>1.12.0</version>
<timestamp>2014-06-21T19:03:49.943Z</timestamp>
<searchResult count="1">
<item>
<itemId>301209856743</itemId>
<title>
DETECTIVE COMICS (1937 Series) #700 Near Mint Comics Book
</title>
<globalId>EBAY-US</globalId>
<primaryCategory>
<categoryId>77</categoryId>
<categoryName>Other</categoryName>
</primaryCategory>
<galleryURL>
http://thumbs4.ebaystatic.com/m/mBYOI1SLUSGe0DL1FmHjdCw/140.jpg
</galleryURL>
<viewItemURL>
http://www.ebay.com/itm/DETECTIVE-COMICS-1937-Series-700-Near-Mint-Comics-Book-/301209856743?pt=US_Comic_Books
</viewItemURL>
<paymentMethod>PayPal</paymentMethod>
<paymentMethod>VisaMC</paymentMethod>
<paymentMethod>Discover</paymentMethod>
<autoPay>false</autoPay>
<location>USA</location>
<country>US</country>
<shippingInfo>
<shippingServiceCost currencyId="USD">4.95</shippingServiceCost>
<shippingType>Flat</shippingType>
<shipToLocations>Worldwide</shipToLocations>
<expeditedShipping>true</expeditedShipping>
<oneDayShippingAvailable>false</oneDayShippingAvailable>
<handlingTime>3</handlingTime>
</shippingInfo>
<sellingStatus>
<currentPrice currencyId="USD">6.0</currentPrice>
<convertedCurrentPrice currencyId="USD">6.0</convertedCurrentPrice>
<sellingState>Active</sellingState>
<timeLeft>P17DT7H31M1S</timeLeft>
</sellingStatus>
<listingInfo>
<bestOfferEnabled>false</bestOfferEnabled>
<buyItNowAvailable>false</buyItNowAvailable>
<startTime>2014-06-09T02:34:50.000Z</startTime>
<endTime>2014-07-09T02:34:50.000Z</endTime>
<listingType>StoreInventory</listingType>
<gift>false</gift>
</listingInfo>
<returnsAccepted>true</returnsAccepted>
<galleryPlusPictureURL>
http://galleryplus.ebayimg.com/ws/web/301209856743_1_0_1.jpg
</galleryPlusPictureURL>
<isMultiVariationListing>false</isMultiVariationListing>
<topRatedListing>false</topRatedListing>
</item>
</searchResult>
<paginationOutput>
<pageNumber>1</pageNumber>
<entriesPerPage>1</entriesPerPage>
<totalPages>111</totalPages>
<totalEntries>111</totalEntries>
</paginationOutput>
<itemSearchURL>
http://www.ebay.com/sch/63/i.html?LH_TitleDesc=1&_nkw=detective+comics+700&_ddo=1&_ipg=1&_pgn=1
</itemSearchURL>
</findItemsAdvancedResponse>
저는 본질적으로 제목, 가격, 배송비 등을 분석하고 싶습니다.
예비 조사에서는 이것이 xmlstarlet
현명한 선택이라고 제안했지만 효과가 없었습니다(나는 내가 뭔가 잘못하고 있음이 틀림없다는 것을 알았습니다).
검색하려고 하면 빈 결과가 나타납니다.
[foouser@foobox fooapp]# cat xmlsample | xmlstarlet sel -t -v "//title"
[foouser@foobox fooapp]#
[foouser@foobox fooapp]# xmlstarlet sel -t -v "//findItemsAdvancedResponse/searchResult/item/title" xmlsample
[foouser@foobox fooapp]#
내가 어디로 잘못 갔는지에 대한 아이디어가 있습니까?
답변1
귀하의 단계를 재현하려고 할 때 두 가지 문제가 발생합니다.
EntityRef: expecting ';'
소스 문서 &
가 &
.
을 사용하여 이 문제를 해결했습니다 sed -i -e 's/&/&/g' xmlresult
.
None of the XPaths matched; to match a node in the default namespace use '_' as the prefix (see section 5.1 in the manual).
다음과 같은섹션 5.1, XPath 쿼리를 추가 -N services=http://www.ebay.com/marketplace/search/v1/services
하고 입력해 보았 더니 이제 유용한 것을 얻었습니다.services:
$ xmlstarlet sel -N services=http://www.ebay.com/marketplace/search/v1/services -t -v '//services:title' result.xml
DETECTIVE COMICS (1937 Series) #700 Near Mint Comics Book