欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ruby實(shí)現(xiàn)網(wǎng)頁(yè)圖片抓取

 更新時(shí)間:2015年06月16日 11:54:04   投稿:hebedich  
本文給大家分享的是個(gè)人使用ruby編寫(xiě)的抓取網(wǎng)頁(yè)圖片的代碼,十分的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。

前段時(shí)間看到很多人寫(xiě)的下妹子腳本,自己也寫(xiě)一個(gè)

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

以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。

相關(guān)文章

最新評(píng)論