ruby1.9.3-Download the network pictures to local and save them by number.

Source: Internet
Author: User
#本程序功能: Download the Web image to local and save it by number. #使用Ruby1.9.3 is written under WINXP_SP3. Require ' Nokogiri ' require ' Open-uri ' #以下 parse the page based on the URL. page = nokogiri::html (open ("http://www.169bb.com/News/2014-12-20/093288.htm")) Arrlen =  page.css (' img '). Lengthmypics = Array.new (Arrlen) #以下 the parsed image address into the mypics array. For x in 0...arrlenmypics[x] = PAGE.CSS (' img ') [x][' src ']end# the following traversal array, saving the network image to local. For x in 0...mypics.lengthuri = Uri.parse (mypics[x]) Rfile = Uri.openwfile = File.Open ("d:\\#{x}.jpg", ' WB ') wfile.puts Rfile.readwfile.closeendputs ' OK ' #写的很差, crawl speed unpleasant, Nokogiri and open-uri many still do not understand.

ruby1.9.3-Download the network pictures to local and save them by number.

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.