This article to share is the individual use Ruby to write the crawl page image code, very simple and practical, the need for small partners can refer to.
Some time ago to see a lot of people write the next sister script, I also write a
|
Module commonhelper require ' Nokogiri ' require ' Open-uri ' def down_load_xmz site_url = ' http://www.xxx.com ' for Inde X_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 ####### #下载图片 def download_img (img_url) begin img_file = Ope N (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. |
The above mentioned is the entire content of this article, I hope you can enjoy.