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 9087201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:39:21+00:00 2026-06-16T21:39:21+00:00

I am making a small scraper for the yahoo.finance.com website. When I make this

  • 0

I am making a small scraper for the yahoo.finance.com website. When I make this request:

symbol = 'AAPL'

@page = Nokogiri::HTML(open("http://finance.yahoo.com/q?s=#{symbol.upcase}&ql=1"))

def marketCap(symbol)
  @page.xpath("//*[(@id = \"yfs_j10_#{symbol.downcase}\")]").text
end

puts marketCap(symbol)

It prints two times the same result.

“495.74B495.74B”

I looked at the source code and the tag is only showing it once

<span id="yfs_j10_f">51.74B</span>

If I use a css selector instead I get the same problem.

Is it a bug or did I made a mistake?

Thanks.

  • 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-06-16T21:39:22+00:00Added an answer on June 16, 2026 at 9:39 pm
    @page.xpath("//*[(@id = \"yfs_j10_#{symbol.downcase}\")]").text
    

    isn’t correct.

    xpath returns a NodeSet, which is similar to an Array. If it contains two elements text will contain both of them:

    @page.xpath("//*[(@id = \"yfs_j10_#{symbol.downcase}\")]").size
    =>2
    

    Instead, use at_xpath to find the first one.

    @page.at_xpath("//*[(@id = \"yfs_j10_#{symbol.downcase}\")]").text
    => "495.74B"
    

    Now, instead of using XPath, which I feel is usually more complicated and less readable, I’d recommend using CSS for your accessor:

    @page.at("#yfs_j10_#{symbol.downcase}").text
    => "495.74B"
    

    Notice that I used at instead of at_css or at_xpath. at senses whether you’re passing an XPath or CSS. It’s generic, and could make a mistake figuring out which to use, but it’s also easier to use. The same is true of search instead of css or xpath. It returns a NodeSet like the other two, but senses which type of accessor it should use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making the small finance management website in php. I have to store
I am making a small HTML page editor. The editor loads a file into
I am making a small section of an app (phone and website) that can
I'm making small web service(1) and I decided to use resteasy to make it.
I'm making a small peer-to-peer app that holds a common collection of objects. This
I was making a small thing in HTML and basically I have some frames
I'm making a small caching actor with Akka 2 and to make the actor
Im making a small python script for auto logon to a website. But i'm
I'm making a small RSS reader and I want it to parse a website
I've been making small scale projects for a while now. I haven't started a

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.