Forum: Ruby HELP-understandable error

74875486613e7c0808a8589427227a46?d=identicon&s=25 Romain Vass (vassili)
on 2013-10-27 02:33
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+'|'+@prix[0..-2]
 puts '---'
end
----------------------
Here his call at line 95:

contenu(y)
----------------------
Here the error:
88:in 'contenu': undefined method 'text' for nil:NilClass
(NoMethodError)from 95:in '<main>'
----------------------
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
.to_i.
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.
23172b6630dc631a134c9bad2fec2a39?d=identicon&s=25 Chris Hulan (Guest)
on 2013-10-27 03:36
(Received via mailing list)
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
74875486613e7c0808a8589427227a46?d=identicon&s=25 Romain Vass (vassili)
on 2013-10-27 03:43
D:/Documents and
Settings/Administrator/Desktop/jpe/JPE-Complet/JPE-C.rb:92:
in `inspect': wrong number of arguments(1 for 0) (ArgumentError)
from D:/Documents and
Settings/Administrator/Desktop/jpe/JPE-Complet/JPE-C.rb:92:in `contenu'
from D:/Documents and
Settings/Administrator/Desktop/jpe/JPE-Complet/JPE-C.rb:100:in `<main>'


Line 92 is the new line 88 (i have update my prog).
The line 100 is the "contenu(y)".
23172b6630dc631a134c9bad2fec2a39?d=identicon&s=25 Chris Hulan (Guest)
on 2013-10-27 03:50
(Received via mailing list)
sorry,
@page.css("tr")[nb.to_i].css("span").inspect
74875486613e7c0808a8589427227a46?d=identicon&s=25 Romain Vass (vassili)
on 2013-10-27 14:12
@page.css("tr")[nb.to_i].css("span").inspect
that make no error
23172b6630dc631a134c9bad2fec2a39?d=identicon&s=25 Chris Hulan (Guest)
on 2013-10-27 23:00
(Received via mailing list)
it should print the object
from your code you should see an array of at least 4 items, since you
are
trying to grab the fourth
If it is printing a list of less then 4 items, or is nil, thats the
cause
of the error
the job then is to figure out why your input is not as you expect
74875486613e7c0808a8589427227a46?d=identicon&s=25 Romain Vass (vassili)
on 2013-10-27 23:16
Attachment: bug.txt (10 KB)
See in the file attached.
23172b6630dc631a134c9bad2fec2a39?d=identicon&s=25 Chris Hulan (Guest)
on 2013-10-27 23:56
(Received via mailing list)
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
that
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
you
just want
to grab the last element use an index of -1
74875486613e7c0808a8589427227a46?d=identicon&s=25 Romain Vass (vassili)
on 2013-10-28 00:02
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
program?

EDIT: how can i put [RESOLVED] in the title (maybe i can't because it's
an e-mail system)?
23172b6630dc631a134c9bad2fec2a39?d=identicon&s=25 Chris Hulan (Guest)
on 2013-10-28 02:06
(Received via mailing list)
sure, glad i could help

merci beaucoup ;)
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.