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.
我需要在<base href='http://url.com'>里面创建一个节点<head>。我可以添加其他类型的节点,如 Nokogiri 文档中所示,但不知道如何添加href. 我怎样才能做到这一点?
<base href='http://url.com'>
<head>
href
您需要通过以下方式访问链接base['href']:
base['href']
doc = Nokogiri::HTML(open('http://www.site.com')) head = doc.at_css('head') base = Nokogiri::XML::Node.new "base", doc base['href'] = 'http://www.site2.com' head.add_child(base)