I have an object which is a child of a < td >
tag. The class is ctext
and the relevant data is within the < b >
tag.tag
I have selected the node using:
td.css(".ctext b")
and it seems to work. I get a result of something like:
< b >Flying< br >< br >At the beginning of each combat, choose first strike, vigilance, or lifelink. Creatures you control gain that ability until end of turn.< /b >
If I use:
td.css(".ctext b").text
to convert it to a string, I get:
FlyingAt the beginning of each combat, choose first strike, vigilance, or lifelink. Creatures you control gain that ability until end of turn.
What I need is to be able to convert the td.css(".ctext b")
, which I think is a Nokogiri xml node to string without stripping the HTML tags. I need to keep the < br >
s.
You want .inner_html
instead of .text
.
The to_s
method on Nokogiri::XML::Node should return the full HTML or XML representation, including tags:
to_s()
Turn this node in to a string. If the document is HTML, this method returns html. If the document is XML, this method returns XML.
So I would try this:
td.css(".ctext b").to_s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With