Advertisement
sinulucky

scrapper!

Feb 7th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.25 KB | None | 0 0
  1. require 'nokogiri'
  2. require 'open-uri'
  3. require 'byebug'
  4.  
  5.  
  6. url = 'http://oploverz.in/page/%d'
  7.  
  8. links = []
  9. (1..3).each do |i|
  10.     page = Nokogiri::HTML(open(url % i))
  11.     page.css('.dtl h2 a[href]').each do |line|
  12.         links << line.attr(:href)
  13.     end
  14. end
  15.  
  16. oploverzs = []
  17.  
  18. links.each do |link|
  19.     page = Nokogiri::HTML(open(links))
  20.     name = page.css(".dtl h1").text.strip
  21.     sinops = page.css(".sinop p").text.strip
  22.  
  23.     smalls = []
  24.     mediums = []
  25.  
  26.  
  27.     link_1 = page.css("soraddl.op-download")[0]
  28.     lista = link_1.css(".soraurl.list-download")[0]
  29.     listb = lista.css("span strong a[href]")[0..3].each do |small|
  30.         smalls << small.attr(:href).strip.split
  31.     end
  32.    
  33.     link_2 = page.css("soraddl.op-download")[0]
  34.     listc = link_2.css(".soraurl.list-download")[1]
  35.     listd = listc.css("span strong a[href]")[0..3].each do |medium|
  36.         mediums << medium.attr(:href).strip.split
  37.     end
  38.     oploverzs << { title: name, sinops: sinops, small: smalls, medium: mediums }
  39. end
  40.  
  41. oploverzs.each do |oploverz|
  42.     @post = Post.new
  43.     @post.title = oploverz[:title]
  44.     @post.sinops = oploverz[:sinops]
  45.     @post.small = oploverz[:small].join(",")
  46.     @post.medium = oploverz[:medium].join(",")
  47.  
  48.     @post.save
  49. end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement