Ruby Implementation page Image capture _ruby topic

Source: Internet
Author: User

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
 
  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
 
 ####### #下载图片
 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
   "
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.