Advertisement
sinulucky

Untitled

Feb 11th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.96 KB | None | 0 0
  1. namespace :scraper do
  2.   desc "Get all the data"
  3.   task awsubs: :environment do
  4.  
  5.  
  6. require 'nokogiri'
  7. require 'open-uri'
  8.  
  9. urltext = 'http://oploverz.in/page/%d'
  10.  
  11.  
  12. links = []
  13. (1..3).each do |i|
  14.     page = Nokogiri::HTML(open(urltext % i))
  15.     page.css('.dtl h2 a[href]').each do |line|
  16.         links << line.attr(:href)
  17.     end
  18. end
  19.  
  20. # links = []
  21. # (1..3).each do |i|
  22. #     page = Nokogiri::HTML(open(urltext % i))
  23. #     page.css('.dtl h2 a[href]').each do |line|
  24. #         links << line.attr(:href)
  25. #     end
  26. # end
  27.  
  28. oploverzs = []
  29.  
  30. smalls = []
  31. mediums = []
  32.  
  33. links.each do |link|
  34.   page = Nokogiri::HTML(open(link))
  35.   page1 = page.css("div#op-single-post.postbody")
  36.   css1 = page1.css("div.epsc")
  37.   css2 = css1.css("div.boxed")
  38.   css3 = css2.css("div.right")
  39.   css4 = css3.css("div.lts")
  40.   css5 = css4.css("ul li div")
  41.   css6 = css5.css("div.dtl")
  42.   name = css6.css("h1.title")
  43.   sinops = page1.css(".animeinfo.sinop p")
  44.  
  45.   # anime_info = page.css(".animeinfo")
  46.   # info_a = anime_info.css(".left")
  47.   # img = info_a.css("img").attr('src')[1]
  48.  
  49.  
  50.   link1 = page.css(".soraddl.op-download")[0]
  51.   lista = link1.css(".soraurl.list-download")[0]
  52.   listb = lista.css("span strong a[href]")[0..3].each do |small|
  53.     smalls << small.attr(:href).strip.split(/ | /)
  54.   end
  55.  
  56.   link2 = page.css(".soraddl.op-download")[0]
  57.   linkc = link2.css(".soraurl.list-download")[1]
  58.   linkd = linkc.css("span strong a[href]")[0..3].each do |medium|
  59.     mediums << medium.attr(:href).strip.split(',')
  60.   end
  61.  
  62.  
  63.   oploverzs << {
  64.     title: name,
  65.     sinops: sinops,
  66.     # small: smalls,
  67.     # medium: mediums
  68.   }
  69.  
  70.  
  71. oploverzs.each do |oploverz|
  72.   @title = Title.new
  73.   @title.title = oploverz[:title]
  74.   @title.sinops = oploverz[:sinops]
  75.   # @title.small = oploverz[:small].join(" | ")
  76.   # @title.medium = oploverz[:medium].join(" | ")
  77.  
  78.   @title.save
  79.  
  80.  
  81.   end
  82. end
  83.  end
  84.  
  85.   desc "Delete All Posts"
  86.   task destroy: :environment do
  87.     Title.destroy_all
  88.   end
  89.  
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement