发布于 2016-01-27 12:36:25 | 111 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Ruby教程,程序狗速度看过来!

Ruby编程语言

Ruby,一种为简单快捷的面向对象编程(面向对象程序设计)而创的脚本语言,在20世纪90年代由日本人松本行弘开发,遵守GPL协议和Ruby License。它的灵感与特性来自于 Perl、Smalltalk、Eiffel、Ada以及 Lisp 语言。


本文给大家分享的是个人使用ruby编写的抓取网页图片的代码,十分的简单实用,有需要的小伙伴可以参考下。

前段时间看到很多人写的下妹子脚本,自己也写一个


module CommonHelper
 
 require 'nokogiri'
 require 'open-uri'
 
 def down_load_xmz
  site_url = "http://www.xxx.com"
 
  for index_page in 1..141
   doc_html = Nokogiri::HTML(open(site_url+'/share/comment-page-'+index_page.to_s))
   doc_html.css("#comments p img").each do |item_img|
    puts item_img[:src]
    download_img(item_img[:src])
   end
  end
 end
 
 ########下载图片
 def download_img(img_url)
  begin
   img_file = open(img_url) { |f| f.read }
   file_name = img_url.split('/').last
   #puts file_name
   open("public/meizi/"+file_name, "wb") { |f| f.write(img_file) }
   return "/public/meizi/"+file_name
  rescue => err
   puts err
   return ''
  end
 end
 
end

以上所述就是本文的全部内容了,希望大家能够喜欢。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务