From: "Иван Бишевац" Date: 2012-09-11T21:03:49+09:00 Subject: Re: Parsing through downloaded html --047d7b33d518e3200c04c96bdda8 Content-Type: text/plain; charset=UTF-8 Sure it could be issue. Here is possible solution: unless searchablefile.at_xpath("//h1[contains(text(), 'pvda')]").nil? sheet[row,column] = searchablefile.at_xpath("//h1[contains(text(), 'pvda')]").content end 2012/9/11 Sybren Kooistra > Alright, perfect. It works. > > However, many variables that I create are based on the POSSIBILITY that > a certain xpath/string exists in a file. If it doesnt, it should > preferably return a nil or a 'no'. > > By using at_xpath and then .content, if an xpath (for example pvda = > searchablefile.at_xpath("//h1[contains(text(), 'pvda')]") returns > nothing, the variable.content (in this case sheet1[row,1] = > pvda.content) does not work, and it no longer runs the rest of the code > (error = undefined method 'content' for nil:nilClass (NoMethodError) > > How can I work around this and/or save boolean on the basis of xpath? > > -- > Posted via http://www.ruby-forum.com/. > > --047d7b33d518e3200c04c96bdda8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sure it could be issue. Here is possible solution:
unless=C2=A0sea= rchablefile.at_xpath("//h1[contains(text(), 'pvda')]").ni= l?
=C2=A0 sheet[row,column] =3D=C2=A0searchablefile.at_xpath(&quo= t;//h1[contains(text(), 'pvda')]").content
end

2012/9/11 Sybren Kooistra <lists@ruby-forum.com>
Alright, perfect. It works.

However, many variables that I create are based on the POSSIBILITY that
a certain xpath/string exists in a file. If it doesnt, it should
preferably return a nil or a 'no'.

By using at_xpath and then .content, if an xpath (for example pvda =3D
searchablefile.at_xpath("//h1[contains(text(), 'pvda')]")= returns
nothing, the variable.content (in this case sheet1[row,1] =3D
pvda.content) does not work, and it no longer runs the rest of the code
(error =3D undefined method 'content' for nil:nilClass (NoMethodErr= or)

How can I work around this and/or save boolean on the basis of xpath?

--047d7b33d518e3200c04c96bdda8--