首页建站经验 ruby实现网页图片抓取

ruby实现网页图片抓取

前段时间看到很多人写的下妹子脚本,自己也写一个module CommonHelperrequire 'nokogiri'require 'open-uri'def down_load_xmzsite_url = "http://www.xxx.com"for index_pa…

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

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

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

本文来自网络,不代表1号站长-站长学院|资讯交流平台立场。转载请注明出处: https://www.1cn.cc/jianzhan/jingyan/17501.html
上一篇JavaScript中的acos()方法使用详解
下一篇 php动态绑定变量的用法
admin

作者: admin

这里可以再内容模板定义一些文字和说明,也可以调用对应作者的简介!或者做一些网站的描述之类的文字或者HTML!

为您推荐

评论列表()

    联系我们

    联系我们

    0898-88888888

    在线咨询: QQ交谈

    邮箱: email@wangzhan.com

    工作时间:周一至周五,9:00-17:30,节假日休息

    关注微信
    微信扫一扫关注我们

    微信扫一扫关注我们

    关注微博
    返回顶部