<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>afly (afly)</title>
    <link>https://ruby-china.org/afly</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>Ruby 的爬虫世界</title>
      <description>&lt;h2 id="引子"&gt;引子&lt;/h2&gt;
&lt;p&gt;人人争说大数据，我先做个小爬虫。&lt;/p&gt;

&lt;p&gt;哪家工具强？&lt;/p&gt;
&lt;h2 id="人肉搜索"&gt;人肉搜索&lt;/h2&gt;
&lt;p&gt;先 google，再翻书，github 里探一探，论坛、知乎 Q 群走一遭&lt;/p&gt;

&lt;p&gt;结论：python 风头劲，ruby 少人问。&lt;/p&gt;

&lt;p&gt;不服！&lt;/p&gt;
&lt;h2 id="http client"&gt;http client&lt;/h2&gt;
&lt;p&gt;要想爬，先上路。&lt;/p&gt;

&lt;p&gt;ruby 社区里的 http 牌老司机可真不少，DSL 手法个个好，用了就别想跑&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/httprb/http" rel="nofollow" target="_blank"&gt;https://github.com/httprb/http&lt;/a&gt;
评价最高，项目说明里有同类项目评测&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/lostisland/faraday" rel="nofollow" target="_blank"&gt;https://github.com/lostisland/faraday&lt;/a&gt;
支持 rack middleware，后起之秀&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Mashape/unirest-ruby" rel="nofollow" target="_blank"&gt;https://github.com/Mashape/unirest-ruby&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/c42/wrest" rel="nofollow" target="_blank"&gt;https://github.com/c42/wrest&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;总的来讲，这些库封装了 http 协议的诸多功能，诸如：form parameters, file uploads and custom body entities、gzip、Basic Authentication natively、timeout、redirect、cache etc.&lt;/p&gt;

&lt;p&gt;可惜 http client 生来只认 http，不识 html。多用于做 API 的客户端，或者 json 爬虫，譬如：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/mgomes/api_auth" rel="nofollow" target="_blank"&gt;https://github.com/mgomes/api_auth&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/ruby-amqp/rabbitmq_http_api_client" rel="nofollow" target="_blank"&gt;https://github.com/ruby-amqp/rabbitmq_http_api_client&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/ruby-amqp/amqp" rel="nofollow" target="_blank"&gt;https://github.com/ruby-amqp/amqp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/alloy/lowdown" rel="nofollow" target="_blank"&gt;https://github.com/alloy/lowdown&lt;/a&gt;
for the HTTP/2 version of the Apple Push Notification Service.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/interagent/heroics" rel="nofollow" target="_blank"&gt;https://github.com/interagent/heroics&lt;/a&gt;
for APIs represented with JSON schema&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="WEB crawl"&gt;WEB crawl&lt;/h2&gt;
&lt;p&gt;不识 html? 不要紧，老司机给你造。&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;nokogiri &lt;a href="http://www.nokogiri.org/" rel="nofollow" target="_blank"&gt;http://www.nokogiri.org/&lt;/a&gt;
最好的 html 解析器，就是安装时有点坑&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/threedaymonk/htmlbeautifier" rel="nofollow" target="_blank"&gt;https://github.com/threedaymonk/htmlbeautifier&lt;/a&gt;
网页不规整，不漂亮，帮你撸一下就好&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;nokogiri 神器在手，百万网页任你爬，不但如此，你还可以在锯子上玩各种花式爬：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/postmodern/nokogiri-diff" rel="nofollow" target="_blank"&gt;https://github.com/postmodern/nokogiri-diff&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;htm5 parser &lt;a href="https://github.com/rubys/nokogumbo" rel="nofollow" target="_blank"&gt;https://github.com/rubys/nokogumbo&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/felipecsl/wombat" rel="nofollow" target="_blank"&gt;https://github.com/felipecsl/wombat&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;XMPP DSL for Ruby &lt;a href="https://github.com/adhearsion/blather" rel="nofollow" target="_blank"&gt;https://github.com/adhearsion/blather&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Open Financial Exchange parser &lt;a href="https://github.com/annacruz/ofx" rel="nofollow" target="_blank"&gt;https://github.com/annacruz/ofx&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;开着 http client 上了路，拿出锯子滤信息，美女照片哗哗哗...停！我要和美女打个招呼&lt;/p&gt;
&lt;h2 id="web interact automation"&gt;web interact automation&lt;/h2&gt;
&lt;p&gt;要想和美女互动，form 这个码头必须拜&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mechanize &lt;a href="https://github.com/sparklemotion/mechanize" rel="nofollow" target="_blank"&gt;https://github.com/sparklemotion/mechanize&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mechanize automatically stores and sends cookies, follows redirects, and can follow links and submit forms&lt;/p&gt;

&lt;p&gt;信息已发送，美女不回复...why?&lt;/p&gt;

&lt;p&gt;你可真是老司机，现在是啥年代，开一辆上世纪的老奔驰（服务端渲染）就想泡到妞？现在车上不装个 js 平板（客户端渲染），你也好意思上路？&lt;/p&gt;
&lt;h2 id="Web Browser Automation"&gt;Web Browser Automation&lt;/h2&gt;
&lt;p&gt;javascript 是个棘手的问题，因为它不是 html 这类文本（常），而是代码（变）。然而爬虫只吃文本，所以必须先要想法将代码执行，变成文本。好比，你要吃包子，你妈拿给你一包面粉，一块肉，一个菜谱，一口锅，来，自己造。&lt;/p&gt;
&lt;h2 id="selenium 1"&gt;selenium 1&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://www.seleniumhq.org/" rel="nofollow" target="_blank"&gt;http://www.seleniumhq.org/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;类似的困难在 WEB 界面自动化测试中也存在，selenium 是解决这类问题的一个 test suit，其原理是："当浏览器启动时，向其中注入 javascript，从而使用这些 js 来驱动浏览器中的 AUT(Application Under Test)..."
嗯，听起来好复杂，而且还要安装一个真实的浏览器！
（实质上，就是 selenium 为浏览器提供一个特别扩展或插件，从而允许 selenium 的测试脚本可以对浏览器的内部对象进行操纵）&lt;/p&gt;
&lt;h3 id="phantomjs"&gt;phantomjs&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://phantomjs.org" rel="nofollow" target="_blank"&gt;http://phantomjs.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;除了测试场景，近年来兴起的 spa 应用同样面临这类问题，即 google 等搜索引擎无法收录这类客户端渲染网页。咋办，有老司机提出：开发一个 headless browser，当 google 等来访问时，就将请求重定向给它，由其生成静态页面后，再返还给 google.&lt;/p&gt;

&lt;p&gt;headless browser，所谓无头浏览器，就是不要脸：）。就是网页的渲染只在内存中进行，而并不输出到输出设备，譬如屏幕（所以你可以按需换头，譬如输出为 html 文件，屏幕截图等等）。&lt;/p&gt;

&lt;p&gt;phantomjs 就是这样一个专供程序员使用的不要脸浏览器，其实质上是基于 WebKit 引擎的一组 JavaScript API 封装，从而方便程序员们去程序化操纵浏览器中的各类对象&lt;/p&gt;
&lt;h3 id="web driver"&gt;web driver&lt;/h3&gt;
&lt;p&gt;以上的解决方案都是典型的太监方案。不过太监热情太高，终于能感动皇帝。&lt;/p&gt;

&lt;p&gt;假如能通过调用浏览器原生 API 以直接驱动浏览器，岂非更好！&lt;/p&gt;

&lt;p&gt;WebDriver 正是这样一个项目：它通过原生浏览器支持以直接控制和操纵浏览器，并且可利用操作系统级的调用模拟用户输入。重要的是，它获得了来自浏览器厂商的原生支持（WebDriver 提供 FirefoxDriver、InternetExplorerDriver、OperaDriver、ChromeDriver 等以及 AndroidDriver、IPhoneDriver 等移动应用测试）。&lt;/p&gt;

&lt;p&gt;实质上，WebDriver 更类似于一个浏览器无关性 API 集（类似于 ODBC 或 DOM），也不与任何测试框架进行绑定，事实上今天它已成长为一项 w3c 标准 &lt;a href="https://w3c.github.io/webdriver/webdriver-spec.html" rel="nofollow" target="_blank"&gt;https://w3c.github.io/webdriver/webdriver-spec.html&lt;/a&gt;&lt;/p&gt;
&lt;h3 id="selenium 2（web driver）"&gt;selenium 2 (web driver)&lt;/h3&gt;
&lt;p&gt;终于，Selenium 和 WebDriver 两个项目合并了，即 Selenium 2，它既支持 Selenium API，又支持 WebDriver API，集 api、工具、环境于一体。
Selenium 本身虽然是 java 编写，但它提供各种语言绑定，譬如 Selenium-WebDrive for ruby&lt;/p&gt;

&lt;p&gt;换句话，老司机们不用换车，也能使用 ruby + selenium2 搞定使用 js 客户端渲染的网页了。&lt;/p&gt;

&lt;p&gt;然而，这还不够。&lt;/p&gt;
&lt;h3 id="watir"&gt;watir&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://watir.github.io/" rel="nofollow" target="_blank"&gt;http://watir.github.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;watir 是和 selenium 类似的工具，它早期使用 IE-only implementation(本质上是一个封装了 MS COM(Component Object Model) 接口的 Ruby 类库，IE 的 COM 接口允许程序访问 IE 浏览器的文档对象模型等)。
随着 WebDriver 的兴起，出现了 Watir-WebDriver 项目，是完全基于 Ruby 语言开发的 WebDriver API 封装（不是 Selenium-WebDrive for ruby binds），最终，2016 年 8 月 Watir 和 Watir-WebDriver 两项目彻底合并，形成了足以对抗 selenium 的另一个完整生态平台。&lt;/p&gt;

&lt;p&gt;why watir？去看看 watir 的示例...&lt;/p&gt;

&lt;p&gt;老司机最爱 ruby，车慢不要紧，驾车姿势要酷炫！&lt;/p&gt;
&lt;h3 id="capybara"&gt;capybara&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://github.com/teamcapybara/capybara" rel="nofollow" target="_blank"&gt;https://github.com/teamcapybara/capybara&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;最后，capybara，一个用户接受度测试框架（Acceptance test framework），同样使用 ruby 开发，rails 应用界面测试的标配，同样必须支持 browser automation。当前它支持如下后台实现：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;rack::test:
缺省，不支持 js&lt;/li&gt;
&lt;li&gt;capybara-webkit:
使用 QtWebKit 引擎 (类似于 python 社区的 splash)，支持 js，但因为并未整个装入浏览器，故速度显著快过 selenium，然而兼容性方面则不如 webdriver&lt;/li&gt;
&lt;li&gt;Poltergeist (PhantomJS) 
相比于 capybara-webkit，no qt ,no X server &lt;/li&gt;
&lt;li&gt;selenium-webdriver:
完整的浏览器支持，当然速度....&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="pincers"&gt;pincers&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/platanus/pincers" rel="nofollow" target="_blank"&gt;https://github.com/platanus/pincers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;提一下这个，似乎也不错，支持 jquery query interface :)&lt;/p&gt;
&lt;h2 id="小结"&gt;小结&lt;/h2&gt;
&lt;p&gt;绕了一大圈，我的小爬虫在哪呢？&lt;/p&gt;

&lt;p&gt;等我定一个小目标先&lt;/p&gt;
&lt;h2 id="附录"&gt;附录&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;watir vs capybara
&lt;a href="https://github.com/watir/watir/issues/444" rel="nofollow" target="_blank"&gt;https://github.com/watir/watir/issues/444&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="http://tutorials.jumpstartlab.com/topics/scraping-with-capybara.html" rel="nofollow" target="_blank"&gt;http://tutorials.jumpstartlab.com/topics/scraping-with-capybara.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/hussar-academy/capybara-learning" rel="nofollow" target="_blank"&gt;https://github.com/hussar-academy/capybara-learning&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/learn-co-students/intro-to-capybara-web-0916" rel="nofollow" target="_blank"&gt;https://github.com/learn-co-students/intro-to-capybara-web-0916&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;烂尾起高楼，待续...&lt;/p&gt;</description>
      <author>afly</author>
      <pubDate>Sat, 03 Dec 2016 19:50:55 +0800</pubDate>
      <link>https://ruby-china.org/topics/31784</link>
      <guid>https://ruby-china.org/topics/31784</guid>
    </item>
    <item>
      <title>征寻杭州之江美院附近的 railser 们</title>
      <description>&lt;p&gt;杭州的之江区是个好地方，，美院附近，尤其如此，，
在凤凰创意园里弄了间办公室，风景如画，办公装修也不错...
准备做一点技术和艺术相结合，科技与文化相碰撞的 app，，
做一个程序员中的艺术家..
如果能用 rails 来做，那是最好..
但文化需要人群，，技术需要人群，，闲时喝茶论道也需要..
文艺的世界有 railser 吗，，railser 们有进军文艺的吗
若有，请与我联系，欢迎来喝茶...
1302522@qq.com&lt;/p&gt;</description>
      <author>afly</author>
      <pubDate>Wed, 05 Jun 2013 23:34:22 +0800</pubDate>
      <link>https://ruby-china.org/topics/11526</link>
      <guid>https://ruby-china.org/topics/11526</guid>
    </item>
    <item>
      <title>[大会八卦:场外报道] 10 号地铁线上悲催的 V 兄与我</title>
      <description>&lt;p&gt;家中有事，临时赶回杭州。&lt;/p&gt;

&lt;p&gt;去往虹桥车站的 10 地铁线上巧遇 viqq 兄，一见投缘：）
两人一路狂聊，然后悲催事情的就一二三... coming&lt;/p&gt;

&lt;p&gt;先是 v 兄错过了换乘 2 号线的车站未下，v 兄说到了虹桥 1 号航站楼再换也行。&lt;/p&gt;

&lt;p&gt;继续狂聊，等到地铁开到了终点，居然发现不是虹桥车站，而是虹航中路-------原来根本就是我们上错了车！&lt;/p&gt;

&lt;p&gt;只得坐回返程车，再换车，终于上对了正确的 10 号线。然后快到 2 号线换乘站时，两人才想起交换联系方式，于是匆匆忙忙中 V 兄下了车，然后------车门关上，我定睛一看地铁图线指示图------悲催的 V 兄啊，你下错车啦，离换 2 号的虹桥 1 号航站楼还有一站呢！&lt;/p&gt;

&lt;p&gt;---------八卦党场外社杭州小组特约报道 :)&lt;/p&gt;</description>
      <author>afly</author>
      <pubDate>Sat, 17 Nov 2012 22:50:38 +0800</pubDate>
      <link>https://ruby-china.org/topics/6848</link>
      <guid>https://ruby-china.org/topics/6848</guid>
    </item>
    <item>
      <title>汉庭快捷上海复旦店宿友召集</title>
      <description>&lt;p&gt;貌似该店本周未时段预定火热，特价房和低价房全部满房，然道都是 Rubyer?!&lt;/p&gt;

&lt;p&gt;同宿友们，冒个头，，周六一早一同去抢座抢福利：）&lt;/p&gt;</description>
      <author>afly</author>
      <pubDate>Wed, 14 Nov 2012 16:32:57 +0800</pubDate>
      <link>https://ruby-china.org/topics/6758</link>
      <guid>https://ruby-china.org/topics/6758</guid>
    </item>
    <item>
      <title>Xiki: 可执行的 wiki 与 gui shell</title>
      <description>&lt;p&gt;Xiki: A shell console with GUI features &lt;a href="http://xiki.org/" rel="nofollow" target="_blank"&gt;http://xiki.org/&lt;/a&gt;
这东西看起来酷啊，用于命令行或者脚本语言的教学绝对好！
用作 rails 的 IDE 也别有风味
研究中...&lt;/p&gt;</description>
      <author>afly</author>
      <pubDate>Thu, 13 Sep 2012 19:44:02 +0800</pubDate>
      <link>https://ruby-china.org/topics/5532</link>
      <guid>https://ruby-china.org/topics/5532</guid>
    </item>
    <item>
      <title>[杭州] 招聘 PHP 程序员 =&gt; Rails 程序员</title>
      <description>&lt;p&gt;加入我们，给你三个转变：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;从 WEB 应用到手机应用&lt;/li&gt;
&lt;li&gt;从 windows 到 linux&lt;/li&gt;
&lt;li&gt;从 php 到 ruby on rails&lt;/li&gt;
&lt;/ul&gt;

&lt;hr&gt;

&lt;p&gt;一、PHP 开发工程师&lt;/p&gt;
&lt;h2 id="岗位说明"&gt;岗位说明&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;在线社区类 WEB 站点的后端开发&lt;/li&gt;
&lt;li&gt;手机应用的服务端开发&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="任职要求"&gt;任职要求&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;一年以上 PHP/MYSQL 平台的 web 后端开发经验&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="加分因素："&gt;加分因素：&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;有使用 Kohana/Symfony/CodeIgniter/Zend framework 等其中任一框架进行开发的经验&lt;/li&gt;
&lt;li&gt;Linux 桌面使用经验或 linux 服务器管理经验&lt;/li&gt;
&lt;li&gt;有学习 ruby on rails 的冲动&lt;/li&gt;
&lt;li&gt;看英文版的 Ebook&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="薪资："&gt;薪资：&lt;/h2&gt;
&lt;p&gt;4K+ ~~~~&lt;/p&gt;

&lt;hr&gt;

&lt;p&gt;二、PHP 高级工程师&lt;/p&gt;
&lt;h2 id="岗位说明"&gt;岗位说明&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;在线社区类 WEB 站点的架构与开发&lt;/li&gt;
&lt;li&gt;手机应用服务端的架构与开发&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="任职要求"&gt;任职要求&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;三年以上 PHP/MYSQL 平台的 web 后端开发经验&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="加分因素："&gt;加分因素：&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;熟练使用 Kohana/Symfony/CodeIgniter/Zend framework 等其中任一框架进行开发&lt;/li&gt;
&lt;li&gt;Linux 桌面使用经验或 linux 服务器管理经验&lt;/li&gt;
&lt;li&gt;有 ruby on rails 基础&lt;/li&gt;
&lt;li&gt;使用英文版的 google&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="薪资："&gt;薪资：&lt;/h2&gt;
&lt;p&gt;8K+ ~~~~~&lt;/p&gt;

&lt;hr&gt;
&lt;h2 id="公司简介"&gt;公司简介&lt;/h2&gt;
&lt;p&gt;母婴类广告公司，依托线下优势向网络进行业务拓展的井喷前夕，需要技术，重视技术，处处都是任由技术驰骋的舞台!
ps: 这里美女很多，男女比例严重失调中...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;公司地点：杭州，中北桥，城建大厦&lt;/li&gt;
&lt;li&gt;联系方式：QQ：1302522，email: 1302522@qq.com&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;应聘特别提醒：面试时，带上你的代码、环境和笔记本，简历都是浮云，键盘上的表演就是一切！&lt;/p&gt;</description>
      <author>afly</author>
      <pubDate>Mon, 07 May 2012 16:57:15 +0800</pubDate>
      <link>https://ruby-china.org/topics/3133</link>
      <guid>https://ruby-china.org/topics/3133</guid>
    </item>
  </channel>
</rss>
