我想在使用Nokogiri解析HTML时在textarea中添加内容:
<textarea placeholder="Describe" title="Describe" name="Describe" value=""></textarea>
这是我设置textarea值的代码:
doc = Nokogiri::HTML( html_content )
textareas = doc.xpath("//textarea")
textareas.each do |r|
r.set_attribute("value","Its my content")
end
这是输出:
<textarea placeholder="Describe" title="Describe" name="Describe" value="Its my content"></textarea>
我想要这样的输出:
<textarea placeholder="Describe" title="Describe" name="Describe" value=""> Its my content </textarea>
答案 0 :(得分:3)
您可以尝试:
doc = Nokogiri::HTML( html_content )
textareas = doc.xpath("//textarea")
textareas.each do |r|
r.content = "Its my content"
end