用Java實(shí)現(xiàn)的網(wǎng)絡(luò)圖像爬蟲,其實(shí)實(shí)現(xiàn)代碼非常簡單,它會在幾分鐘內(nèi)實(shí)現(xiàn),本文是武林技術(shù)頻道小編帶給大家的實(shí)現(xiàn)ruby網(wǎng)頁圖片抓取的方法,希望對你有所幫助!
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īng)明了實(shí)現(xiàn)ruby網(wǎng)頁圖片抓取的方法,不過在實(shí)際操作的時候,程序員一定要謹(jǐn)慎,選擇武林技術(shù)頻道網(wǎng)進(jìn)行學(xué)習(xí),會讓您受益匪淺哦!
新聞熱點(diǎn)
疑難解答
圖片精選