ruby实现网页图片抓取
前段时间看到很多人写的下妹子脚本,自己也写一个
moduleCommonHelper
require'nokogiri'
require'open-uri'
defdown_load_xmz
site_url="http://www.xxx.com"
forindex_pagein1..141
doc_html=Nokogiri::HTML(open(site_url+'/share/comment-page-'+index_page.to_s))
doc_html.css("#commentspimg").eachdo|item_img|
putsitem_img[:src]
download_img(item_img[:src])
end
end
end
########下载图片
defdownload_img(img_url)
begin
img_file=open(img_url){|f|f.read}
file_name=img_url.split('/').last
#putsfile_name
open("public/meizi/"+file_name,"wb"){|f|f.write(img_file)}
return"/public/meizi/"+file_name
rescue=>err
putserr
return''
end
end
end
以上所述就是本文的全部内容了,希望大家能够喜欢。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短