Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定一个 xpath 说
我可以做类似的事情:
doc.xpath("/html/body/a").wrap("<span></span>")
span并用标签包装所有链接?
span
doc.xpath('/html/body/a').each{ |a| a.swap("<span>#{a}</span>") }
找到了更好的解决方案(根据@Phrogz 进行编辑)
doc.search('a').wrap('<span/>')