0514-86177077
9:00-17:00(工作日)
前段時間看到很多人寫的下妹子腳本,自己也寫一個
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
標簽:鄂州 河北 松原 宜春 六安 自貢 石嘴山 淄博
上一篇:解析proxy代理模式在Ruby設計模式開發(fā)中的運用
下一篇:Ruby使用REXML庫來解析xml格式數(shù)據(jù)的方法
Copyright ? 1999-2012 誠信 合法 規(guī)范的巨人網(wǎng)絡通訊始建于2005年
蘇ICP備15040257號-8