Advertisement
sinulucky

Untitled

Feb 10th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.76 KB | None | 0 0
  1. require 'nokogiri'
  2. require 'open-uri'
  3. # require 'byebug'
  4.  
  5. urltext = 'http://oploverz.in/page/%d'
  6.  
  7.  
  8. links = []
  9. (1..3).each do |i|
  10.     page = Nokogiri::HTML(open(urltext % i))
  11.     page.css('.thumbnail a[href]').each do |line|
  12.         links << line.attr(:href)
  13.     end
  14. end
  15.  
  16. # links = []
  17. # (1..3).each do |i|
  18. #     page = Nokogiri::HTML(open(urltext % i))
  19. #     page.css('.dtl h2 a[href]').each do |line|
  20. #         links << line.attr(:href)
  21. #     end
  22. # end
  23.  
  24. oploverzs = []
  25.  
  26. smalls = []
  27. mediums = []
  28.  
  29. links.each do |link|
  30.   page = Nokogiri::HTML(open(link))
  31.   name = page.css(".featured2 h1").text.strip
  32.   sinops = page.css(".sinop p").text.strip
  33.   # anime_info = page.css(".animeinfo")
  34.   # info_a = anime_info.css(".left")
  35.   # img = info_a.css("img").attr('src')[1]
  36.  
  37.  
  38.   link1 = page.css(".soraddl.op-download")[0]
  39.   lista = link1.css(".soraurl.list-download")[0]
  40.   listb = lista.css("span strong a[href]")[0..3].each do |small|
  41.     smalls << small.attr(:href).strip.split(/ | /)
  42.   end
  43.  
  44.   link2 = page.css(".soraddl.op-download")[0]
  45.   linkc = link2.css(".soraurl.list-download")[1]
  46.   linkd = linkc.css("span strong a[href]")[0..3].each do |medium|
  47.     mediums << medium.attr(:href).strip.split(',')
  48.   end
  49.  
  50.  
  51.   oploverzs << {
  52.     title: name,
  53.     sinops: sinops,
  54.     # small: smalls,
  55.     # medium: mediums
  56.   }
  57.  
  58. #   images << {
  59. #     url: img
  60. #   }
  61.  
  62. # end
  63.  
  64.  
  65. oploverzs.each do |oploverz|
  66.   @title = Title.new
  67.   @title.title = oploverz[:title]
  68.   @title.sinops = oploverz[:sinops]
  69.   # @title.small = oploverz[:small].join(" | ")
  70.   # @title.medium = oploverz[:medium].join(" | ")
  71.  
  72.   @title.save
  73.  
  74.   # images.each do |image|
  75.   #   @image = Image.new
  76.   #   @image.url = image[:url]
  77.   #   @image.post_id = @post.id
  78.   #   @image.save
  79.  
  80.   end
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement