下面是编程之家 jb51.cc 通过网络收集整理的代码片段。
编程之家小编现在分享给大家,也给大家做个参考。
# encoding: ASCII-8BIT require 'open-uri' def master title = ["系统工具","图形图像","多媒体类","游戏娱乐","数据库类","模块控件","行业软件","网络相关"] path = ["etools","eimage","emedia","egame","edata","ecom","eTrade","enetwork"] Dir.mkdir("#{$run_file}/downfile") if !File.directory?("#{$run_file}/downfile") for i in 0..7 Dir.mkdir("#{$run_file}/downfile/#{title[i]}") if !File.directory?("#{$run_file}/downfile/#{title[i]}") caiji(title[i],path[i]) end end def caiji (title,path) url = "http://www.5a5x.com/wode_source/#{path}/" page_count = getCount "#{url}10.html" if page_count % 10 == 0 page_count = page_count / 10 else page_count = page_count / 10 + 1 end for i in 1..page_count puts "正在处理#{title}第#{i}页,共#{page_count}页" html = open("#{url}#{i}.html").read a = 0 while true a = html.index('<dt><a href="',a) break if a == nil a = a + 13 b = html.index('"',a) download_page_url = html[a,b - a] a = b + 18 b = html.index('<',a) file_title = html[a,b - a] download_url = getDownloadUrl download_page_url puts "正在下载:#{file_title}.zip" tmp = File.new("#{$run_file}/downfile/#{title}/#{file_title}.zip","w") tmp.binmode tmp.write open("http://www.5a5x.com/#{download_url}","r").read tmp.close end end end def getDownloadUrl download_page_url html = open("http://www.5a5x.com/#{download_page_url}").read a = html.index("<a href='down.PHP?a_k=") + 9 b = html.index("'",a) url = html[a,b - a] html = open("http://www.5a5x.com/#{url}").read a = html.index('<a href="download.PHP?a_k=') + 9 b = html.index('"',a) return html[a,b - a] end def getRunFile a = __FILE__.rindex "/" return __FILE__[0,a] end def getCount url html = open(url).read a = html.index("总数:<b>") + 9 b = html.index("<",b - a].to_i end $run_file = getRunFile master()
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。