Multi line tags?

12 views
Skip to first unread message

Peter Chudinov

unread,
Jul 5, 2016, 11:48:04 AM7/5/16
to nokogiri-talk
page.css("tr[class=rowA]/td[3]").text

fails with

NoMethodError: undefined method `text' for nil:NilClass


supposedly it happens because original html looks like this:

<td>
"some text in here"
</td>

How do I solve it?

Hassan Schroeder

unread,
Jul 5, 2016, 12:54:22 PM7/5/16
to nokogi...@googlegroups.com
Simplified:

2.3.1 (main):0 > example = "<tr><td>some text in here</td></tr>"
=> "<tr><td>some text in here</td></tr>"
2.3.1 (main):0 > example_plus = "<tr><td>\nsome text in here\n</td></tr>"
=> "<tr><td>\nsome text in here\n</td></tr>"
2.3.1 (main):0 >
Nokogiri::HTML::DocumentFragment.parse(example).css("tr/td").text
=> "some text in here"
2.3.1 (main):0 >
Nokogiri::HTML::DocumentFragment.parse(example_plus).css("tr/td").text
=> "\nsome text in here\n"
2.3.1 (main):0 >

It doesn't appear to be a problem with newlines, but perhaps you
can gist a more complete test case?

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote
Reply all
Reply to author
Forward
0 new messages