이 게시물의 하단에 hpricot xml이 주어지면 .each를 사용하지 않고 "항목"을 어떻게 선택하겠습니까? 문서의 모든 단일 조각은 오직 하나 "항목"이 있기 때문에이 경우에는 무의미이 hpricot 객체의 요소는 어떻게 찾습니까?
@res.items.each do |item|
# do stuff
end
의 변형을 사용합니다. 이 권리를 얻기 위해 노력하는 지난 나이에 머리카락을 찢어 내고 있습니다.
편집 자세한 정보를 추가합니다 :
좋아하므로 초기 의견에서 판단, 나는 어딘가에 내가 더 많은 정보를 제공합니다 점을 누락.
Amazon에서 제품 정보를 검색하려면 amazon-ecs이라는 루비 보석을 사용하고 있습니다. 보석의 사이트에 정말 무슨 뜻인지 이해가 안 숫돌로 이제
A generic Ruby Amazon Product Advertising API (previously known as E-commerce REST API) using Hpricot. It uses Response and Element wrapper classes for easy access to the REST API XML output. It is generic, so you can extend Amazon::Ecs to support the other not-implemented operations easily; and the response object just wraps around Hpricot element object, instead of providing one-to-one object/attributes to XML elements map.
으로 설명하지만 포장 응답 개체에 대한 비트가이 어렵게 무엇을 의심! 나는이 수행 할 때
기본적으로 :
@res = Amazon::Ecs.item_lookup(ean, options_hash)
다음 나는 "디버그 @res"을 인쇄, 내가 얻을 나는 아래에 무엇을 가지고있다.
희망 하시겠습니까? 최종 편집
Hpricot을의 XML :
<Amazon::Ecs::Response:0xa4449cc @doc=#<Hpricot::Doc
{xmldecl "<?xml version=\"1.0\" ?>"}
{elem <itemlookupresponse xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05">
{elem <operationrequest>
{elem <httpheaders>
{emptyelem <header name="UserAgent" value="Ruby">}
</HTTPHeaders>}
{elem <requestid> "b89bad91-f5a1-4daf-87f2-d309dded35d6" </RequestId>}
{elem <arguments>
{emptyelem <argument name="Operation" value="ItemLookup">}
{emptyelem <argument name="SearchIndex" value="Books">}
{emptyelem <argument name="Signature" value="dasdasdsadsadsafdfdsfsdsasadsadsd">}
{emptyelem <argument name="ItemId" value="9780307463746">}
{emptyelem <argument name="IdType" value="ISBN">}
{emptyelem <argument name="AWSAccessKeyId" value="sdasdsadsadsadsadsadd">}
{emptyelem <argument name="Timestamp" value="2011-02-17T15:08:09Z">}
{emptyelem <argument name="Service" value="AWSECommerceService">}
</Arguments>}
{elem <requestprocessingtime> "0.0252220000000000" </RequestProcessingTime>}
</OperationRequest>}
{elem <items>
{elem <request>
{elem <isvalid> "True" </IsValid>}
{elem <itemlookuprequest>
{elem <condition> "New" </Condition>}
{elem <deliverymethod> "Ship" </DeliveryMethod>}
{elem <idtype> "ISBN" </IdType>}
{elem <merchantid> "Amazon" </MerchantId>}
{elem <offerpage> "1" </OfferPage>}
{elem <itemid> "9780307463746" </ItemId>}
{elem <responsegroup> "Small" </ResponseGroup>}
{elem <reviewpage> "1" </ReviewPage>}
{elem <searchindex> "Books" </SearchIndex>}
</ItemLookupRequest>}
</Request>}
{elem <item>
{elem <asin> "0307463745" </ASIN>}
{elem <detailpageurl> "http://rads.stackoverflow.com/amzn/click/0307463745" </DetailPageURL>}
{elem <smallimage>
{elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL._SL75_.jpg" </URL>}
{elem <height units="pixels"> "75" </Height>}
{elem <width units="pixels"> "50" </Width>}
</SmallImage>}
{elem <mediumimage>
{elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL._SL160_.jpg" </URL>}
{elem <height units="pixels"> "160" </Height>}
{elem <width units="pixels"> "106" </Width>}
</MediumImage>} {elem <largeimage> {elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL.jpg" </URL>} {elem <height units="pixels"> "500" </Height>} {elem <width units="pixels"> "331" </Width>} </LargeImage>} {elem <imagesets> {elem <imageset category="primary"> {elem <swatchimage> {elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL._SL30_.jpg" </URL>} {elem <height units="pixels"> "30" </Height>} {elem <width units="pixels"> "20" </Width>} </SwatchImage>} {elem <smallimage> {elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL._SL75_.jpg" </URL>} {elem <height units="pixels"> "75" </Height>} {elem <width units="pixels"> "50" </Width>} </SmallImage>} {elem <mediumimage> {elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL._SL160_.jpg" </URL>} {elem <height units="pixels"> "160" </Height>} {elem <width units="pixels"> "106" </Width>} </MediumImage>} {elem <largeimage> {elem <url> "http://ecx.images-amazon.com/images/I/41Qz6afdrLL.jpg" </URL>} {elem <height units="pixels"> "500" </Height>} {elem <width units="pixels"> "331" </Width>} </LargeImage>} </ImageSet>} </ImageSets>}
{elem <itemattributes>
{elem <author> "Jason Fried" </Author>}
{elem <author> "David Heinemeier Hansson" </Author>}
{elem <manufacturer> "Crown Business" </Manufacturer>}
{elem <productgroup> "Book" </ProductGroup>}
{elem <title> "Rework" </Title>}
</ItemAttributes>}
</Item>}
</Items>}
</ItemLookupResponse>}
XML 문서 아니다 :
그런 다음 Hpricot을 개체를 사용할 수 있어야합니다. 인쇄 된 Hpricot 객체입니다. 이 엉터리 구문을 파싱하려고하시는 지 아니면 먼저 Hpricot 객체를 다시 생성 하시겠습니까? –
좋아, 내가 여기서하고있는 일로 인해 꽤 잃어버린 것 같아 OP를 편집하여 더 많은 정보를 제공하도록 편집했다. –