2015-06-06 16 views
6

Tôi đang cố gắng để cạo hình ảnh từ các trang web. Tôi đang sử dụng Nokogiri và XPath cho đến nay với thành công hạn chế. Đối với một trang web điển hình có HTML có img và src, tôi có thể sử dụng:Ruby on Rails XPath Json Cạo hình ảnh

tmp2 = Nokogiri::HTML(open(site_url)) 
tmp2.xpath("//img/@src").each do |src| 
    ...do whatever 
end 

Tuy nhiên, một số trang web như Amazon và eBay chỉ kích hoạt một số hình ảnh nhất định bằng javascript. Nếu tôi nhìn vào mã, tôi có thể xem dữ liệu trong mảng. Ví dụ, từ Amazon (nguồn: http://www.amazon.com/Threads-Thought-Womens-Dreams-X-Small/dp/B00T46V758/ref=sr_1_5?s=apparel&ie=UTF8&qid=1433555447&sr=1-5):

<script type="text/javascript"> 
P.when('jQuery', 'cf').execute(function($, cf){ 
    P.load.js('http://z-ecx.images-amazon.com/images/G/01/browser-scripts/imageBlock-udp-airy/imageBlock-udp-airy-4060168860._V1_.js'); 
}); 

P.when('A', 'jQuery', 'ImageBlockATF', 'cf').register('ImageBlockBTF', function(A, $, imageBlockATF, cf){ 
    var data = {"indexToColor":[],"burjImageBlock":0,"isSwatchHoverConsistent":1,"heroFocalPoint":null,"visualDimensions":["color_name"],"productGroupID":"apparel_display_on_website","newVideoMissing":0,"useIV":0,"useClickZoom":null,"useChildVideos":0,"numColors":7,"logMetrics":0,"defaultColor":"initial","airyConfig":{"enableContinuousPlay":null,"installFlashButtonText":"Install Flash Player","contentTitle":null,"autoplayCutOffTimeSeconds":null,"ageGate":{"monthNames":["January","February","March","April","May","June","July","August","September","October","November","December"],"deniedPrompt":"We're sorry. You are not old enough to watch this video.","submitText":"Submit","prompt":"This video is not intended for all audiences. What date were you born?"},"videoAds":null,"videoUnsupportedPrompt":"Sorry, this video is unsupported on this browser.","desiredMode":null,"swfUrl":"http://g-ecx.images-amazon.com/images/G/01/vap/video/airy2/prod/2.0.1102.0/flash/AiryBasicRenderer._V304902271_.swf","isAutoplayEnabled":null,"installFlashPrompt":"Adobe Flash Player is required to watch this video.","isLiveStream":null,"regionCode":"NA","contentId":null,"playbackErrorPrompt":"Sorry, an error has occurred while attempting video playback. Please try again later.","contentMinAge":null,"isForesterTrackingDisabled":null,"streamingUrls":null,"parentId":null,"foresterMetadataParams":{"client":"Dpx","requestId":"1MX7VHFRVAS6TWY64BXC","marketplaceId":"ATVPDKIKX0DER","session":"182-9511970-7757812","method":"Apparel.ImageBlock"},"jsUrl":"http://z-ecx.images-amazon.com/images/G/01/vap/video/airy2/prod/2.0.1102.0/js/airy.chromeless._V304902265_.js"},"mainImageMaxSizes":null,"staticStrings":{"playVideo":"Click to play video","rollOverToZoom":"Roll over image to zoom in","images":"Images","video":"video","clickToZoom":"Click on image to zoom in","touchToZoom":"Touch the image to zoom in","videos":"Videos","close":"Close","pleaseSelect":"Please select","clickToExpand":"Click to open expanded view","allMedia":"All Media"},"notThumbnailClickImmersiveView":1,"gIsNewTwister":1,"title":"Threads 4 Thought Women's Tabitha Basic Tank Top","ivRepresentativeAsin":{"6":"B00T46V76W","4":"B00WM3O7ES","1":"B00T46YZES","3":"B00WM3NLPE","2":"B00T46VD16","5":"B00T46VGXQ"},"mainImageSizes":[[342,445],[385,500],[425,550],[466,606],[522,679]],"isQuickview":0,"ipadVideoSizes":[[340,444],[384,500]],"colorToAsin":{"Coral Dreams":{"asin":"B00T46V76W"},"Heather Grey":{"asin":"B00WM3NLPE"},"Black":{"asin":"B00T46YZES"},"White":{"asin":"B00T46VGXQ"},"Deep Blue Sea":{"asin":"B00T46VD16"},"Sea Glass":{"asin":"B00WM3O7ES"}},"thumbExperimentEnabledValue":1,"showLITBOnClick":0,"videoSizes":[[342,445],[384,500]],"stretchyGoodnessWidth":[1280,1440,1640,1800],"autoplayVideo":0,"hoverZoomIndicator":"","sitbReftag":"","useHoverZoom":1,"staticImages":{"zoomOut":"http://g-ecx.images-amazon.com/images/G/01/detail-page/cursors/zoom-out._V184888738_.bmp","hoverZoomIcon":"http://g-ecx.images-amazon.com/images/G/01/img11/apparel/UX/DP/icon_zoom._V138923886_.png","zoomIn":"http://g-ecx.images-amazon.com/images/G/01/detail-page/cursors/zoom-in._V184888790_.bmp","zoomLensBackground":"http://g-ecx.images-amazon.com/images/G/01/apparel/rcxgs/tile._V211431200_.gif","videoThumbIcon":"http://g-ecx.images-amazon.com/images/G/01/Quarterdeck/en_US/images/video._V183716339_SX38_SY50_CR,0,0,38,50_.gif","spinner":"http://g-ecx.images-amazon.com/images/G/01/ui/loadIndicators/loading-large_labeled._V192238949_.gif","zoomInCur":"http://g-ecx.images-amazon.com/images/G/01/detail-page/cursors/zoomIn._V323082799_.cur","videoSWFPath":"http://g-ecx.images-amazon.com/images/G/01/Quarterdeck/en_US/video/20110518115040892/Video._V178668404_.swf","arrow":"http://g-ecx.images-amazon.com/images/G/01/javascripts/lib/popover/images/light/sprite-vertical-popover-arrow._V186877868_.png","zoomOutCur":"http://g-ecx.images-amazon.com/images/G/01/detail-page/cursors/zoomOut._V323082798_.cur"},"videos":[],"gPreferChildVideos":0,"altsOnLeft":1,"ivImageSetKeys":{"Coral Dreams":"6","Heather Grey":"3","Black":"1","initial":0,"White":"5","Deep Blue Sea":"2","Sea Glass":"4"},"useHoverZoomIpad":"","isUDP":1,"alwaysIncludeVideo":0,"widths":[1280,1440,1640,1800],"maxAlts":7,"useChromelessVideoPlayer":1,"mainImageHeightPartitions":null}; 
    data["customerImages"] = eval('[]'); 
    data["colorImages"] = {"Coral Dreams":[{"large":"http://ecx.images-amazon.com/images/I/41FGlhksmtL.jpg","variant":"MAIN","hiRes":"http://ecx.images-amazon.com/images/I/81iXQbkcpiL._UL1500_.jpg","thumb":"http://ecx.images-amazon.com/images/I/41FGlhksmtL._SR38,50_.jpg","main":{"http://ecx.images-amazon.com/images/I/81iXQbkcpiL._UX466_.jpg":["466","606"],"http://ecx.images-amazon.com/images/I/81iXQbkcpiL._UX522_.jpg":["522","679"],"http://ecx.images-amazon.com/images/I/81iXQbkcpiL._UY550_.jpg":["423","550"],"http://ecx.images-amazon.com/images/I/81iXQbkcpiL._UX342_.jpg":["342","445"],"http://ecx.images-amazon.com/images/I/81iXQbkcpiL._UY500_.jpg":["385","500"]}},{"large":"http://ecx.images-amazon.com/images/I/41XR9o0cV-L.jpg","variant":"BACK","hiRes":"http://ecx.images-amazon.com/images/I/81bVmFiRu0L._UL1500_.jpg","thumb":"http://ecx.images-amazon.com/images/I/41XR9o0cV-L._SR38,50_.jpg","main":{"http://ecx.images-amazon.com/images/I/81bVmFiRu0L._UY500_.jpg":["385","500"],"http://ecx.images-amazon.com/images/I/81bVmFiRu0L._UX522_.jpg":["522","679"],"http://ecx.images-amazon.com/images/I/81bVmFiRu0L._UX342_.jpg":["342","445"],"http://ecx.images-amazon.com/images/I/81bVmFiRu0L._UX466_.jpg":["466","606"],"http://ecx.images-amazon.com/images/I/81bVmFiRu0L._UY550_.jpg":["423","550"]}}],"Heather Grey":[{"large":"http://ecx.images-amazon.com/images/I/41f-8R8Eu-L.jpg","variant":"MAIN","hiRes":"http://ecx.images-amazon.com/images/I/81dTYkBL%2BxL._UL1500_.jpg","thumb":"http://ecx.images-amazon.com/images/I/41f-8R8Eu-L._SR38,50_.jpg","main":{"http://ecx.images-amazon.com/images/I/81dTYkBL%2BxL._UX466_.jpg":["466","606"],"http://ecx.images-amazon.com/images/I/81dTYkBL%2BxL._UY500_.jpg":["385","500"],"http://ecx.images-amazon.com/images/I/81dTYkBL%2BxL._UY550_.jpg":["423","550"],"http://ecx.images-amazon.com/images/I/81dTYkBL%2BxL._UX522_.jpg":["522","679"],"http://ecx.images-amazon.com/images/I/81dTYkBL%2BxL._UX342_.jpg":["342","445"]}},{"large":"http://ecx.images-amazon.com/images/I/41gLiFBbcdL.jpg","variant":"BACK","hiRes":"http://ecx.images-amazon.com/images/I/81ua3AXCpJL._UL1500_.jpg","thumb":"http://ecx.images-amazon.com/images/I/41gLiFBbcdL._SR38,50_.jpg","main":{"http://ecx.images-amazon.com/images/I/81ua3AXCpJL._UX342_.jpg":["342","445"],"http://ecx.images-amazon.com/images/I/81ua3AXCpJL._UY550_.jpg":["423","550"],"http://ecx.images-amazon.com/images/I/81ua3AXCpJL._UY500_.jpg":["385","500"],"http://ecx.images-amazon.com/images/I/81ua3AXCpJL._UX522_.jpg":["522","679"],"http://ecx.images-amazon.com/images/I/81ua3AXCpJL._UX466_.jpg":["466","606"]}}],"Black":[{"large":"http://ecx.images-amazon.com/images/I/41BxSpfEM7L.jpg","variant":"MAIN","hiRes":"http://ecx.images-amazon.com/images/I/81%2BTW8762BL._UL1500_.jpg","thumb":"http://ecx.images-amazon.com/images/I/41BxSpfEM7L._SR38,50_.jpg","main":{"http://ecx.images-amazon.com/images/I/81%2BTW8762BL._UY550_.jpg":["423","550"],"http://ecx.images-amazon.com/images/I/81%2BTW8762BL._UX342_.jpg":["342","445"],"http://ecx.images-amazon.com/images/I/81%2BTW8762BL._UX522_.jpg":["522","679"],"http://ecx.images-amazon.com/images/I/81%2BTW8762BL._UY500_.jpg":["385","500"],"http://ecx.images-amazon.com/images/I/81%2BTW8762BL._UX466_.jpg":["466","606"]}},{"large":"http://ecx.images-amazon.com/images/I/41Gf%2BW-cPTL.jpg","variant":"BACK","hiRes":"http://ecx.images-amazon.com/images/I/81SJwuaCspL._UL1500_.jpg","thumb":"http://ecx.images-amazon.com/images/I/41Gf%2BW-cPTL._SR38,50_.jpg","main":{"http://ecx.images-amazon.com/images/I/81SJwuaCspL._UY500_.jpg":["385","500"],"http://ecx.images-amazon.com/images/I/81SJwuaCspL._UX522_.jpg":["522","679"],"http://ecx.images-amazon.com/images/I/81SJwuaCspL._UX342_.jpg":["342","445"],"http://ecx.images-amazon.com/images/I/81SJwuaCspL._UX466_.jpg":["466","606"],"http://ecx.images-amazon.com/images/I/81SJwuaCspL._UY550_.jpg":["423","550"]}}],"White":[{"large":"http://ecx.images-amazon.com/images/I/41tElK2wPKL.jpg","variant":"MAIN","hiRes":"http://ecx.images-amazon.com/images/I/81kKgU75rIL._UL1500_.jpg","thumb":"http://ecx.images-amazon.com/images/I/41tElK2wPKL._SR38,50_.jpg","main":{"http://ecx.images-amazon.com/images/I/81kKgU75rIL._UY550_.jpg":["423","550"],"http://ecx.images-amazon.com/images/I/81kKgU75rIL._UX522_.jpg":["522","679"],"http://ecx.images-amazon.com/images/I/81kKgU75rIL._UY500_.jpg":["385","500"],"http://ecx.images-amazon.com/images/I/81kKgU75rIL._UX342_.jpg":["342","445"],"http://ecx.images-amazon.com/images/I/81kKgU75rIL._UX466_.jpg":["466","606"]}},{"large":"http://ecx.images-amazon.com/images/I/31lEDIs4cqL.jpg","variant":"BACK","hiRes":"http://ecx.images-amazon.com/images/I/81OBgvbUR7L._UL1500_.jpg","thumb":"http://ecx.images-amazon.com/images/I/31lEDIs4cqL._SR38,50_.jpg","main":{"http://ecx.images-amazon.com/images/I/81OBgvbUR7L._UX466_.jpg":["466","606"],"http://ecx.images-amazon.com/images/I/81OBgvbUR7L._UX342_.jpg":["342","445"],"http://ecx.images-amazon.com/images/I/81OBgvbUR7L._UX522_.jpg":["522","679"],"http://ecx.images-amazon.com/images/I/81OBgvbUR7L._UY500_.jpg":["385","500"],"http://ecx.images-amazon.com/images/I/81OBgvbUR7L._UY550_.jpg":["423","550"]}}],"Deep Blue Sea":[{"large":"http://ecx.images-amazon.com/images/I/41oNq3KmSGL.jpg","variant":"MAIN","hiRes":"http://ecx.images-amazon.com/images/I/81MtZtmxVLL._UL1500_.jpg","thumb":"http://ecx.images-amazon.com/images/I/41oNq3KmSGL._SR38,50_.jpg","main":{"http://ecx.images-amazon.com/images/I/81MtZtmxVLL._UX342_.jpg":["342","445"],"http://ecx.images-amazon.com/images/I/81MtZtmxVLL._UX522_.jpg":["522","679"],"http://ecx.images-amazon.com/images/I/81MtZtmxVLL._UY550_.jpg":["423","550"],"http://ecx.images-amazon.com/images/I/81MtZtmxVLL._UY500_.jpg":["385","500"],"http://ecx.images-amazon.com/images/I/81MtZtmxVLL._UX466_.jpg":["466","606"]}},{"large":"http://ecx.images-amazon.com/images/I/41AJgd1OuYL.jpg","variant":"BACK","hiRes":"http://ecx.images-amazon.com/images/I/81uLEksrYFL._UL1500_.jpg","thumb":"http://ecx.images-amazon.com/images/I/41AJgd1OuYL._SR38,50_.jpg","main":{"http://ecx.images-amazon.com/images/I/81uLEksrYFL._UX342_.jpg":["342","445"],"http://ecx.images-amazon.com/images/I/81uLEksrYFL._UY500_.jpg":["385","500"],"http://ecx.images-amazon.com/images/I/81uLEksrYFL._UX522_.jpg":["522","679"],"http://ecx.images-amazon.com/images/I/81uLEksrYFL._UX466_.jpg":["466","606"],"http://ecx.images-amazon.com/images/I/81uLEksrYFL._UY550_.jpg":["423","550"]}}],"Sea Glass":[{"large":"http://ecx.images-amazon.com/images/I/418vg-re8oL.jpg","variant":"MAIN","hiRes":"http://ecx.images-amazon.com/images/I/81YgtD-bEwL._UL1500_.jpg","thumb":"http://ecx.images-amazon.com/images/I/418vg-re8oL._SR38,50_.jpg","main":{"http://ecx.images-amazon.com/images/I/81YgtD-bEwL._UX342_.jpg":["342","445"],"http://ecx.images-amazon.com/images/I/81YgtD-bEwL._UX522_.jpg":["522","679"],"http://ecx.images-amazon.com/images/I/81YgtD-bEwL._UX466_.jpg":["466","606"],"http://ecx.images-amazon.com/images/I/81YgtD-bEwL._UY500_.jpg":["385","500"],"http://ecx.images-amazon.com/images/I/81YgtD-bEwL._UY550_.jpg":["423","550"]}},{"large":"http://ecx.images-amazon.com/images/I/41lcpC41VSL.jpg","variant":"BACK","hiRes":"http://ecx.images-amazon.com/images/I/814%2B6ZLwIxL._UL1500_.jpg","thumb":"http://ecx.images-amazon.com/images/I/41lcpC41VSL._SR38,50_.jpg","main":{"http://ecx.images-amazon.com/images/I/814%2B6ZLwIxL._UY500_.jpg":["385","500"],"http://ecx.images-amazon.com/images/I/814%2B6ZLwIxL._UX342_.jpg":["342","445"],"http://ecx.images-amazon.com/images/I/814%2B6ZLwIxL._UX522_.jpg":["522","679"],"http://ecx.images-amazon.com/images/I/814%2B6ZLwIxL._UX466_.jpg":["466","606"],"http://ecx.images-amazon.com/images/I/814%2B6ZLwIxL._UY550_.jpg":["423","550"]}}]}; 
    data["heroImage"] = {}; 
    data["landingAsinColor"] = 'Coral Dreams'; 
    data["shouldApplyResizeFix"] = false; 

    return data; 
}); 

</script> 

Các tên tập tin tôi muốn lấy không có src (tức http://ecx.images-amazon.com/images/I/81%2BTW8762BL.UY500.jpg) Trong trường hợp này, mảng được gọi là "data [" colorImages "]

... Nhưng tôi không thể mã hóa cứng bất cứ điều gì ở đây vì điều tương tự xảy ra trên eBay ... ví dụ: http://www.ebay.com/itm/Summer-Women-Casual-Chiffon-Loose-Tops-Batwing-Short-Sleeve-Loose-T-Shirt-Blouse-/351411949784?pt=LH_DefaultDomain_0&var=&hash=item51d1c8d0d8

các tên tập tin tôi cần ở đây là trong "enImgCarousel"

trên lưu ý phụ, khi tôi u se bookmarklet javascript sau cho mỗi url để có được hình ảnh, tôi có thể có được những hình ảnh chính xác:

a=''; 
for (b=0;b<document.images.length;b++){ 
    a+='<img src='+document.images[b].src+'><br>'}; 
    ifa=''){ 
     document.writea+'</center>'); 
     void(document.close()) 
    }else{ 
     alert('No images!') 
    } 

Về Nokogiri và XPath, tôi cũng đã thử với:

tmp2.xpath("//img").each do |src|... 

tmp2.xpath("html//img").each do |src| 

Bất kỳ ý tưởng nào tôi nên làm điều này hoặc hướng đi nào?

Trả lời

-1

Xin lỗi, khi tôi đăng câu trả lời từ điện thoại di động, tôi không thể viết mã đầy đủ ngay lập tức, tuy nhiên, tôi có thể cung cấp cho bạn một cách. Bạn nên sử dụng Mechanize với selenium-webdriver & watir thay vì chỉ Nokogiri.

Sử dụng Cơ giới hóa, bạn sẽ có thể xử lý các yếu tố đến từ JavaScript. Bạn có thể giả lập di chuyển thực tế trên trình duyệt, tức là bạn có thể mã để nhấp vào liên kết/nút, bạn có thể đợi tải hình ảnh và sau đó có thể xóa nó. Và tất cả điều này có thể được thực hiện bằng cách sử dụng Mechanize rất dễ dàng.

+0

mechanize sẽ không thực hiện bất kỳ hoạt Javascript, vì vậy nó không thể "xử lý các yếu tố đến từ JavaScript ". Có thể nhấp vào các nút, nhưng nếu các nút đó kích hoạt bất kỳ tác vụ JavaScript nào hoặc JavaScript cố gắng tự động sửa đổi trang, những thay đổi đó sẽ không được nhìn thấy. Tắt JavaScript trong trình duyệt và điều hướng qua trang web và bạn sẽ thấy những gì Cơ chế sẽ thấy. –

+0

@theTinMan Như đã đề cập trong câu trả lời, bạn cần phải sử dụng cơ giới hóa với selenium-webdriver và watir để xử lý các thành phần động – RAJ

+0

Nếu bạn đang sử dụng selen hoặc watir thì Mechanize là không cần thiết. Sử dụng chúng để điều hướng và Nokogiri bởi vì nó là lõi phân tích của Mechanize và là trọng lượng nhẹ hơn. –

-1

Bạn đang cố gắng tạo cơ sở dữ liệu của các mục cạnh tranh với giá cả, v.v ...?
Bạn đang cố gắng lấy toàn bộ danh mục hoặc người bán riêng lẻ? Lý do tại sao tôi hỏi là bạn có thể nhận nguồn cấp dữ liệu RSS của các mục mà mỗi người bán liệt kê nếu họ đã bật tính năng đó. Bằng cách này, bạn không phải lãng phí thời gian cạo một trang khi bạn có thể lấy dữ liệu trung tâm từ một nguồn cấp dữ liệu RSS.

Khi phân tích trang web, tùy thuộc vào vị trí của bạn trên trang web (bạn đã đề cập băng chuyền), các chỉ mục bạn đang gặp phải là từ các hình thu nhỏ đại diện cho hình ảnh lớn hơn.
Tôi khuyên bạn nên xem xét API eBay và API Amazon và tìm kiếm nguồn cấp dữ liệu RSS cho người bán trước. Khi có quá nhiều vấn đề về Javascript, trang web sẽ tải các trình chiếu và băng chuyền xoay động, vì vậy bạn sẽ phải sử dụng Mechanize (như RAJ được đề xuất ở trên) hoặc Beautiful Soup hoặc Selenium để nhận các trang web được hiển thị đầy đủ, trong đó tất cả các hình ảnh đang ở trạng thái có thể xóa.

Hãy đăng nguồn của bạn nếu có bất kỳ điều gì khác mà tôi có thể trợ giúp.

+0

Vấn đề tôi đang gặp phải là người dùng có thể yêu cầu lấy hình ảnh từ bất kỳ trang web nào, không chỉ eBay và Amazon. Đối với hầu hết các trang web, thường xuyên cạo hình ảnh (theo mã tôi có ở trên) hoạt động tuyệt vời; nhưng đối với một số trang web (và tôi sẽ không biết trước những trang web nào), tôi cần một cái gì đó để cạo sâu hơn. Những gì tôi cần là xem mã trang và trả về tất cả các tệp hình ảnh được liệt kê (không chỉ những tệp có thuộc tính img src). Tiền thưởng hết hạn sau một vài phút và tôi ước tôi có thể mở rộng nó vì tôi chưa có thời gian để thử Cơ chế mặc dù nó có vẻ đầy hứa hẹn. Tôi chưa từng nghe về Beautiful Soup. Tôi sẽ xem xét nó – purplerice

+1

Bất kỳ chương trình nào cụ thể "hiển thị" javascript sẽ giải quyết vấn đề này vì nó xóa chỉ mục, v.v. và cung cấp cho bạn hình ảnh và các mục tham chiếu javascript khác một cách rõ ràng. – miniscule

+0

Hãy đánh dấu đây là câu trả lời để tôi có thể nhận tiền thưởng trước khi thời gian gia hạn hết hạn - - cảm ơn! – miniscule

0

Đây là cách thay thế để giải quyết những gì bạn muốn đạt được; bạn có thể sử dụng capybara và poltergeist và tôi đã nhận được cái bạn muốn nhận. Vì vậy, tôi giả sử bạn không phải đi sâu vào javascript với giải pháp này.

Nếu bạn cạo, tôi khuyên bạn nên xem xét capybara với poltergeist, bạn có thể tìm thấy nhiều nguồn để tham khảo.

Sau đây là mã tôi đã thử. Hy vọng nó sẽ giúp!

require 'capybara' 
require 'capybara/dsl' 
require 'capybara/poltergeist' 

Capybara.register_driver :poltergeist_debug do |app| 
    Capybara::Poltergeist::Driver.new(app, inspector: true) 
end 

Capybara.javascript_driver = :poltergeist_debug 
Capybara.current_driver = :poltergeist_debug 

# Amazon Case 
visit_site('https://www.amazon.com/dp/B00T46V758/?tag=stackoverfl08-20') 
doc_amazon = Nokogiri::HTML.parse(page.html) 
doc_amazon.xpath("//img/@src").each do |src| 
    p src.value 
end 

#ebay case 
visit_site('https://www.ebay.com/itm/Summer-Women-Casual-Chiffon-Loose-Tops-Batwing-Short-Sleeve-Loose-T-Shirt-Blouse-/351411949784?pt=LH_DefaultDomain_0&var=&hash=item51d1c8d0d8')  
doc_ebay = Nokogiri::HTML.parse(page.html) 
doc_ebay.xpath("//img/@src").each do |src| 
    p src.value 
end 

nếu bạn muốn thâm nhập vào nó ... (có vẻ như bạn không muốn)

doc.xpath("//div[@id='imgTagWrapperId']/img").attribute('src').value 
# => "https://images-na.ssl-images-amazon.com/images/I/81%2BTW8762BL._UX453_.jpg" 

doc.xpath("//div[@id='mainImgHldr']/img[@id='icImg']").attribute('src').value 
# => "https://i.ebayimg.com/images/g/dtAAAOSwpdpVZuU~/s-l300.jpg"