Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6230037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:40:31+00:00 2026-05-24T09:40:31+00:00

doc.xpath(‘//img’) #this will get some results doc.xpath(‘//img[@class=productImage]’) #and this gets nothing at all doc.xpath(‘//div[@id=someID]’)

  • 0
doc.xpath('//img') #this will get some results
doc.xpath('//img[@class="productImage"]') #and this gets nothing at all
doc.xpath('//div[@id="someID"]') # and this won't work either

I don’t know what went wrong here,I double checked the HTML source,There are plenty of img tag which contains the attribute(class=”productImage”).

It’s like the attribute selector just won’t work.

Here is the URL which the HTML source come from.

http://www.amazon.cn/s/ref=nb_sb_ss_i_0_1?__mk_zh_CN=%E4%BA%9A%E9%A9%AC%E9%80%8A%E7%BD%91%E7%AB%99&url=search-alias%3Daps&field-keywords=%E4%B8%93%E5%85%AB&x=0&y=0&sprefix=%E4%B8%93

please do me a favor if you got some spare time.Parse the HTML content like I do see if you can solve this one

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:40:31+00:00Added an answer on May 24, 2026 at 9:40 am

    The weird thing is if you use open-uri on that page you get a different result than when using something like curl or wget.

    However when you change the User-Agent you actually get probably the page you are looking for:

    Analysis:

    require 'rubygems'
    require 'nokogiri'
    require 'open-uri'
    require 'pp'  
    
    URL = 'http://www.amazon.cn/...'
    
    def analyze_html(file)
       doc = Nokogiri.HTML(file)
       pp   doc.xpath('//img').map { |i| i[:class] }.compact.reject(&:empty?)
       puts doc.xpath('//div').map { |i| i[:class] }.grep(/productImage/).count
       puts doc.xpath('//div[@class="productImage"]//img').count
       pp   doc.xpath('//div[@class="productImage"]//img').map { |i| i[:src] }
    end
    
    puts "Attempt 1:"
    analyze_html(open(URL))
    
    puts "Attempt 2:"
    analyze_html(open(URL, "User-Agent" => "Wget/1.10.2"))
    

    Output:

    Attempt 1:
    ["default navSprite"]
    0
    0
    []
    Attempt 2:
    ["default navSprite", "srSprite spr_kindOfSortBtn"]
    16
    16
    ["http://ec4.images-amazon.com/images/I/51fOb3ujSjL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/513UQ1xiaSL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/41zKxWXb8HL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/51bj6XXAouL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/516GBhDTGCL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/51ADd3HSE6L._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/51CbB-7kotL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/51%2Bw40Mk51L._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/519Gny1LckL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/51Dv6DUF-WL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/51uuy8yHeoL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/51T0KEjznqL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/419WTi%2BdjzL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/51QTg4ZmMmL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/51l--Pxw9TL._AA115_.jpg",
     "http://ec4.images-amazon.com/images/I/51gehW2qUZL._AA115_.jpg"]
    

    Solution:

    1. Use User-Agent: Wget/1.10.2
    2. Use xpath('//div[@class="productImage"]//img')
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am parsing some XML using Nokogiri and XPath. When I do this: doc.xpath('//Order/child::node()').each
According to the doc, object is all new-style classes' base class. And AFAIK, the
This Ruby code using Nokogiri doc.xpath(//tbody).remove removes the children of the <tbody> (as well
I have this xpath pattern: tags = doc.xpath('/html/body//a[text() = ' + name.encode('utf8') + ']/@href'
I need to remove an image with the give src img_src = http://domain/img.jpg @doc.xpath(//img[@src='#{img_src}'])[0].remove
using nokogiri, doc = Nokogiri::HTML(your_html) doc.xpath(//text()).to_s this does the job, however, it puts everything
doc.xpath(//div[@id='Ci_']).each_with_index do |div,i| parse_file.puts #{div.at_xpath(./*[@class='class1']).text} parse_file.puts #{div.at_xpath(./*[@class='class2']).text} There are two links in class2 and
var doc = w.document; doc.open('application/CSV','replace'); doc.charset = utf-8; doc.write(all,hello); doc.close(); if(doc.execCommand(SaveAs,null,file.csv)) { window.alert(saved );
I have a stax doc with some embedded scripting to check if today's day
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(content); var nodes = doc.DocumentNode.SelectNodes(//div[@class=\noprint res\]/div); if (nodes !=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.