ironsand
ironsand

Reputation: 15151

How to get html text with line break by Nokogiri

There is a html text like this:

html = '<div class="foo"><span class="bar">text<br>with line break</span></div>'
doc = Nokogiri::HTML(html)

And I want to get the text text<br>with line break. Currently I'm using

doc.css("span").to_html.match(/<span .+?>(.*)<\/span>/){ $1 }

Is there simpler way to make it? If possible I want to avoid using regular expression.

Upvotes: 2

Views: 1171

Answers (1)

aidan
aidan

Reputation: 9576

Have you tried the inner_html method?

doc.css("span").inner_html

Upvotes: 3

Related Questions