我想在文本区添加内容,同时使用Nokogiri解析HTML:
<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>
您可以尝试:
doc = Nokogiri::HTML( html_content )
textareas = doc.xpath("//textarea")
textareas.each do |r|
r.content = "Its my content"
end