HELP-understandable error

Hello all,
here is my method lines 85-92:

def contenu(nb)
@titre = @page.css(“tr”)[nb.to_i].css(“h2”).css(“a”).text
@lieu = @page.css(“tr”)[nb.to_i].css(“a”).css(“p”)[0].text
@prix = @page.css(“tr”)[nb.to_i].css(“span”)[4].text
puts @titre
puts @lieu+’|’[email protected][0…-2]
puts ‘—’

Here his call at line 95:


Here the error:
88:in ‘contenu’: undefined method ‘text’ for nil:NilClass
(NoMethodError)from 95:in ‘’

My question: why the price-line(prix) work differently of the two others
before her?
She works fine if i put a number, and don’t work with the “nb” whithout
This may be a link with the character € (it’s for that the -2 at line
90, because it show “?” instead).

If you are french, i am too, et mon anglais n’est pas assez avancé pour
tout comprendre en cette langue.

Thanks to you.

looks like ‘css(“span”)[4]’ is returning nil
insert a line before line 88:
inspect @page.css(“tr”)[nb.to_i].css(“span”)

to see if the data matches what you expect

D:/Documents and
in inspect': wrong number of arguments(1 for 0) (ArgumentError) from D:/Documents and Settings/Administrator/Desktop/jpe/JPE-Complet/JPE-C.rb:92:incontenu’
from D:/Documents and
Settings/Administrator/Desktop/jpe/JPE-Complet/JPE-C.rb:100:in `’

Line 92 is the new line 88 (i have update my prog).
The line 100 is the “contenu(y)”.


it should print the object
from your code you should see an array of at least 4 items, since you
trying to grab the fourth
If it is printing a list of less then 4 items, or is nil, thats the
of the error
the job then is to figure out why your input is not as you expect

that make no error

See in the file attached.

Oh yes it was that, the element i will is the 4th not the 5th, i am so
stupid (because i know array start at 0).

Very much thanks to you, can i quote your name like helper in my

EDIT: how can i put [RESOLVED] in the title (maybe i can’t because it’s
an e-mail system)?

array indexes start at 0
the element at index 4 is the fifth

looking at the output, some of the rows have less then 5 elements, and
is where you get the nil when using index 4

It appears that in all the output the last element is the same, so if
just want
to grab the last element use an index of -1

sure, glad i could help

merci beaucoup :wink: