# Nokogiri and xpath for changing value on the web

**URL:** <https://www.ruby-forum.com/t/nokogiri-and-xpath-for-changing-value-on-the-web/180524>\
**Category:** Ruby\
**Created:** [December 21, 2009, 8:34am UTC](https://www.ruby-forum.com/t/nokogiri-and-xpath-for-changing-value-on-the-web/180524 "2009-12-21T08:34:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![soujiro0725](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/57b2e6/32.png) [@soujiro0725](https://www.ruby-forum.com/u/soujiro0725)\
**Post date:** [December 21, 2009, 8:34am UTC](https://www.ruby-forum.com/t/nokogiri-and-xpath-for-changing-value-on-the-web/180524/1 "2009-12-21T08:34:14Z")

</div>

ruby 1.8.6  
Ubuntu 8.04  
nokogiri 1.4.0

Hi. I am trying to get a number(Nikkei 225) from the web site, “Google  
Finance”. It’s a number that indicates the average of major stock  
prices, which changes in real-time.

> **[Google Finance - Stock Market Prices, Real-time Quotes & Business News](https://www.google.com/finance/)**
>
> Google Finance provides real-time market quotes, international exchanges, up-to-date financial news, and analytics to help you make more informed trading and investment decisions.

## here is the code I tried.

require ‘rubygems’  
require ‘nokogiri’  
require ‘open-uri’

url = “[http://www.google.com/finance?q=INDEXNIKKEI:.N225](http://www.google.com/finance?q=INDEXNIKKEI:.N225)”

doc = Nokogiri::HTML(open(url).read)

path1 = “/html/body/div[@id=‘ref\_15513676\_l’]”

## p doc.xpath(path1).text()

but it gives nothing. But no error, though.  
The full xpath for the number, which appears big and bold in the near  
top of the page is

* * *

## /html/body/div[@id=‘outer-wrapper’]/div[@id=‘body-wrapper’]/div[6]/div[@id=‘rt-content’]/div/div[2]/div[2]/div[@id=‘market-data-div’]/div[@id=‘price-panel’]/div[1]/span/span[@id=‘ref\_15513676\_l’]/span[1]

then I guessed that the important part would be the last one followed  
from “[@id…” in comparison to the Dow average which is below.

* * *

## /html/body/div[@id=‘outer-wrapper’]/div[@id=‘body-wrapper’]/div[6]/div[@id=‘rt-content’]/div/div[2]/div[2]/div[@id=‘market-data-div’]/div[@id=‘price-panel’]/div[1]/span/span[@id=‘ref\_983582\_l’]

What’s wrong with my code? Could anyone help me out?

soichi

---

<div class="post-metadata">

**Author:** ![soujiro0725](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/57b2e6/32.png) [@soujiro0725](https://www.ruby-forum.com/u/soujiro0725)\
**Post date:** [December 21, 2009, 8:46am UTC](https://www.ruby-forum.com/t/nokogiri-and-xpath-for-changing-value-on-the-web/180524/2 "2009-12-21T08:46:18Z")

</div>

Soichi I. wrote:

> path1 = “/html/body/div[@id=‘ref\_15513676\_l’]”

Your XPATH is wrong try

path1 = “/html/body/div//span[@id=‘ref\_15513676\_l’]”

Edward

---

<div class="post-metadata">

**Author:** ![soujiro0725](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/57b2e6/32.png) [@soujiro0725](https://www.ruby-forum.com/u/soujiro0725)\
**Post date:** [December 21, 2009, 8:53am UTC](https://www.ruby-forum.com/t/nokogiri-and-xpath-for-changing-value-on-the-web/180524/3 "2009-12-21T08:53:27Z")

</div>

It worked!  
Thanks Edward for such a quick reply. I appreciate it.

soichi
