Aro*_*pan 7 html ruby nokogiri
我有一个< td >标签的子对象.类是ctext,相关数据在< b >tag.tag内
我使用以下方法选择了节点:
td.css(".ctext b")
Run Code Online (Sandbox Code Playgroud)
它似乎工作.我得到的结果如下:
< 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 >
Run Code Online (Sandbox Code Playgroud)
如果我使用:
td.css(".ctext b").text
Run Code Online (Sandbox Code Playgroud)
把它转换成字符串,我得到:
FlyingAt the beginning of each combat, choose first strike, vigilance, or lifelink. Creatures you control gain that ability until end of turn.
Run Code Online (Sandbox Code Playgroud)
我需要的是能够将td.css(".ctext b")我认为是Nokogiri xml节点的字符串转换为字符串而不剥离HTML标记.我需要保留< br >s.
Nokogiri :: XML :: Nodeto_s上的方法应返回完整的HTML或XML表示形式,包括标签:
to_s()
将此节点转为字符串。如果文档是HTML,则此方法返回html。如果文档是XML,则此方法返回XML。
所以我会尝试这样的:
td.css(".ctext b").to_s
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7558 次 |
| 最近记录: |