html_doc = Nokogiri::HTML("<html><body><h1>Mr. Belvedere Fan Club</h1></body></html>")
xml_doc = Nokogiri::XML("<root><aliens><alien><name>Alf</name></alien></aliens></root>")
f = File.open("blossom.xml")
doc = Nokogiri::XML(f)
f.close
require 'open-uri'
doc = Nokogiri::HTML(open("http://www.xxx.com/"))
<root>
<sitcoms>
<sitcom>
<name>Married with Children</name>
<characters>
<character>Al Bundy</character>
<character>Bud Bundy</character>
<character>Marcy Darcy</character>
</characters>
</sitcom>
<sitcom>
<name>Perfect Strangers</name>
<characters>
<character>Larry Appleton</character>
<character>Balki Bartokomous</character>
</characters>
</sitcom>
</sitcoms>
<dramas>
<drama>
<name>The A-Team</name>
<characters>
<character>John "Hannibal" Smith</character>
<character>Templeton "Face" Peck</character>
<character>"B.A." Baracus</character>
<character>"Howling Mad" Murdock</character>
</characters>
</drama>
</dramas>
</root>
@doc = Nokogiri::XML(File.open("shows.xml"))
@doc.xpath("//character")
@doc.xpath("//dramas//character")
characters = @doc.css("sitcoms name")
# => ["<name>Married with Children</name>", "<name>Perfect Strangers</name>"]
@doc.css("dramas name").first # => "<name>The A-Team</name>"
@doc.at_css("dramas name") # => "<name>The A-Team</name>"
<parts> <!-- Alice's Auto Parts Store --> <inventory xmlns="http://alicesautoparts.com/"> <tire>all weather</tire> <tire>studded</tire> <tire>extra wide</tire> </inventory> <!-- Bob's Bike Shop --> <inventory xmlns="http://bobsbikes.com/"> <tire>street</tire> <tire>mountain</tire> </inventory> </parts>
@doc = Nokogiri::XML(File.read("parts.xml"))
car_tires = @doc.xpath('//car:tire', 'car' => 'http://alicesautoparts.com/')
bike_tires = @doc.xpath('//bike:tire', 'bike' => 'http://bobsbikes.com/')
<feed xmlns="http://www.w3.org/2005/Atom"> <title>Example Feed</title> <link href="http://example.org/"/> <updated>2003-12-13T18:30:02Z</updated> <author> <name>John Doe</name> </author> <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id> <entry> <title>Atom-Powered Robots Run Amok</title> <link href="http://example.org/2003/12/13/atom03"/> <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> <updated>2003-12-13T18:30:02Z</updated> <summary>Some text.</summary> </entry> </feed>
@doc.xpath('//xmlns:title')
# => ["<title>Example Feed</title>", "<title>Atom-Powered Robots Run Amok</title>"]
@doc.css('xmlns|title')
@doc.css('title')
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有