nokogiri如何使用
直接来个简单的代码实例就明白啦!
require 'nokogiri' xml_data=<<XML
<library>
<NAME><![CDATA[Favorite Books]]></NAME>
<book ISBN="">
<title>To Kill A Mockingbird</title>
<description><![CDATA[Description#1]]></description>
<author>Harper Lee</author>
</book>
<book ISBN="">
<title>Catcher in the Rye</title>
<description><![CDATA[This is an extremely intense description.]]></description>
<author>J. D. Salinger</author>
</book>
<book ISBN="">
<title>Murphy\'s Gambit</title>
<description><![CDATA[Daughter finds her dad!]]></description>
<author>Syne Mitchell</author>
</book>
</library>
XML # 载入数据
doc = Nokogiri::XML(xml_data) # 使用css获取到结点,遍历读取到Book对象中
doc.css('book').each do |node|
children = node.children Book.create(
:isbn => node['ISBN'],
:title => children.css('title').inner_text,
:description => children.css('description').inner_text,
:author => children.css('author').inner_text
)
end
nokogiri如何使用的更多相关文章
- mac gem install nokogiri error
Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /Users/angela/.rbenv/versions/1.9 ...
- Ruby:Nokogiri
阅读推荐: Nokogiri的用法我推荐三篇非常给力的文章: http://ruby.bastardsbook.com/chapters/html-parsing/ http://ruby.basta ...
- Nokogiri爬虫教程
Parsing HTML with Nokogiri http://ruby.bastardsbook.com/chapters/html-parsing/ Inspecting a Webpage' ...
- [翻译][Nokogiri官方教程] 解析HTML/XML文档 / Parsing an HTML/XML Document
From a String From a File From the Internet Parse Options Encoding 原文: Parsing an HTML/XML Document ...
- nokogiri
Nokogiri的用法我推荐三篇非常给力的文章:http://ruby.bastardsbook.com/chapters/html-parsing/http://ruby.bastardsbook. ...
- Ruby nokogiri 解析xml的简单实例
require 'nokogiri'XML_FILE = "C:\\Users\\chenpassion\\Desktop\\20130806.xml"xml = Nokogiri ...
- Ruby爬虫header发送cookie,nokogiri解析html数据
之前用php写过一个爬虫,同样是获取局域网的网站数据,这次我使用相同的网络环境,更低的电脑配置,使用ruby来再次爬虫,惊人的发现ruby使用自带的类库net/http爬取速度要远远超过php的cur ...
- nokogiri Fail install on Ruby 2.3 for Windows #1456 <From github>
Q: gem install railson nokogiri install fail with error: 'nokogiri requires Ruby version < 2.3, & ...
- CocoaPod 使用方法
huangyichengdeMacBook-Pro:~ Jack$ pod search AFNetworking/Library/Ruby/Site/2.0.0/rubygems.rb:250:in ...
随机推荐
- windows下面安装casperjs
因为需要 就学习了一下casperjs,CasperJS是一个开源的导航脚本处理和测试工具,基于PhantomJS(前端自动化测试工具)编写.由于casperjs对PhantomJS的依赖性,所以需要 ...
- JreeeChart入门
JFreeChart主要用来各种各样的图表,这些图表包括:饼图.柱状图(普通柱状图以及堆栈柱状图).线图.区域图.分布图.混合图.甘特图以及一些仪表盘等等 (源代码下载) 示例程序运用的jar包: j ...
- 鼠标滚轮控制侧边div上下翻动效果
css部分: <style> * { margin: 0; padding: 0;} .wrap { width: 1000px; margin: 0 auto; overflow: hi ...
- 第三节 构造一个简单的Linux系统MenuOS——20135203齐岳
第三节 构造一个简单的Linux系统MenuOS By 20135203齐岳 Linux内核源代码 arch/ 支持不同cpu的源代码 Documentations/ 文档存储 init/ 内核启动相 ...
- 使用Settings.settings存储用户的个性化配置
1.在vs中设计要存储的字段,如:zbl,注意范围选择用户 读取: var aa = Properties.Settings.Default.zbl; 写入: Properties.Settings. ...
- sql server 子找父和父找子
父找子 with RTD1 as( select Id,pid from Sys_XCode ), RTD2 as( select * from RTD1 where id=1 union all s ...
- Selenium - CSS Selector
Selenium - CSS Selector http://www.cnblogs.com/bugua/archive/2012/08/16/2641647.html 昨天我练习了用CSS(即层 ...
- Oracle Metadata Management (OMM)元数据管理 12.2.1发布
元数据管理元数据管理是解决大量关键业务和技术挑战的基础,这些挑战包括元数据实体有多少,上游数据变化的影响,在浏览器中提供友好的分析展现界面,或提供企业范围内的元数据现状分析和改进视图.OMM是一款基于 ...
- js传url中文参数乱码问题
$("#btnKeyWord").click(function () { window.open("/Atraction/Atraction.aspx?keyword=& ...
- Python OpenCV —— Arithmetic
图案的算术操作. # -*- coding: utf-8 -*- """ Created on Wed Sep 28 11:54:47 2016 @author: Adm ...