Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace :scraper do
- desc "Fetch the data from scraper"
- task scrape: :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
- names = []
- links.each do |link|
- page2 = Nokogiri::HTML(open(links))
- page2.css('.dtl h1').each do |name|
- names << name.text.strip
- end
- end
- sinops = []
- links.each do |link|
- page3 = Nokogiri::HTML(open(links))
- page3.css('.sinop p').each do |sinop|
- sinops << sinop.text.strip
- end
- end
- smalls = []
- links.each do |link|
- page4 = Nokogiri::HTML(open(links))
- link_1 = page4.css('.soraddl.op-download')[0]
- list_d = link_1.css('.soraurl.list-download')[0]
- linkb = list_d.css('span strong a[href]')[0..3].each do |small|
- smalls << small.attr(:href).strip.split
- end
- end
- oploverzs = []
- mediums = []
- links.each do |link|
- page5 = Nokogiri::HTML(open(links))
- link_2 = page5.css('.soraddl.op-download')[0]
- lista = link_2.css('.soraurl.list-download')[1]
- linkb = lista.css('span strong a[href]')[4..7].each do |medium|
- mediums << medium.attr(:href).strip.split
- end
- end
- oploverzs << {
- title: names,
- sinops: sinops,
- small: smalls,
- medium: mediums
- }
- oploverzs.each do |oploverz|
- @post = Post.new
- @post.title = oploverz[names]
- @post.sinops = oploverz[sinops]
- @post.small = oploverz[smalls]
- @post.medium = oploverz[mediums]
- @post.save
- end
- end
- desc "TODO"
- task destroy_all_posts: :environment do
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement