Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace :scraper do
- desc "Get all the data"
- task awsubs: :environment do
- require 'nokogiri'
- require 'open-uri'
- urltext = 'http://oploverz.in/page/%d'
- links = []
- (1..3).each do |i|
- page = Nokogiri::HTML(open(urltext % i))
- page.css('.dtl h2 a[href]').each do |line|
- links << line.attr(:href)
- end
- end
- # links = []
- # (1..3).each do |i|
- # page = Nokogiri::HTML(open(urltext % i))
- # page.css('.dtl h2 a[href]').each do |line|
- # links << line.attr(:href)
- # end
- # end
- oploverzs = []
- smalls = []
- mediums = []
- links.each do |link|
- page = Nokogiri::HTML(open(link))
- page1 = page.css("div#op-single-post.postbody")
- css1 = page1.css("div.epsc")
- css2 = css1.css("div.boxed")
- css3 = css2.css("div.right")
- css4 = css3.css("div.lts")
- css5 = css4.css("ul li div")
- css6 = css5.css("div.dtl")
- name = css6.css("h1.title")
- sinops = page1.css(".animeinfo.sinop p")
- # anime_info = page.css(".animeinfo")
- # info_a = anime_info.css(".left")
- # img = info_a.css("img").attr('src')[1]
- link1 = page.css(".soraddl.op-download")[0]
- lista = link1.css(".soraurl.list-download")[0]
- listb = lista.css("span strong a[href]")[0..3].each do |small|
- smalls << small.attr(:href).strip.split(/ | /)
- end
- link2 = page.css(".soraddl.op-download")[0]
- linkc = link2.css(".soraurl.list-download")[1]
- linkd = linkc.css("span strong a[href]")[0..3].each do |medium|
- mediums << medium.attr(:href).strip.split(',')
- end
- oploverzs << {
- title: name,
- sinops: sinops,
- # small: smalls,
- # medium: mediums
- }
- oploverzs.each do |oploverz|
- @title = Title.new
- @title.title = oploverz[:title]
- @title.sinops = oploverz[:sinops]
- # @title.small = oploverz[:small].join(" | ")
- # @title.medium = oploverz[:medium].join(" | ")
- @title.save
- end
- end
- end
- desc "Delete All Posts"
- task destroy: :environment do
- Title.destroy_all
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement