Commit 3c7e899c by Ngô Trung Hưng

fix autoload

parent 37488f20
Pipeline #789 canceled with stages
in 0 seconds
...@@ -10,7 +10,7 @@ module Venjob ...@@ -10,7 +10,7 @@ module Venjob
class Application < Rails::Application class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version. # Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2 config.load_defaults 5.2
config.autoload_paths << Rails.root.join('lib') config.autoload_paths << Rails.root.join('lib/src')
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers # Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading # -- all .rb files in that directory are automatically loaded after loading
......
...@@ -5,8 +5,7 @@ require 'open-uri' ...@@ -5,8 +5,7 @@ require 'open-uri'
require 'logger' require 'logger'
# Crawler data # Crawler data
module Src module Base
module Base
class Base class Base
attr_accessor :job, :page attr_accessor :job, :page
...@@ -87,5 +86,4 @@ module Src ...@@ -87,5 +86,4 @@ module Src
exist_experience? ? page.xpath('//ul//li[position()=2]//p')[1].text.strip : '' exist_experience? ? page.xpath('//ul//li[position()=2]//p')[1].text.strip : ''
end end
end end
end
end end
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
require 'open-uri' require 'open-uri'
# Crawler data # Crawler data
module Src class Crawler
class Crawler
attr_accessor :number_link attr_accessor :number_link
def initialize(number_link) def initialize(number_link)
...@@ -63,5 +62,4 @@ module Src ...@@ -63,5 +62,4 @@ module Src
logger.error "Crawler data companies has error: #{e}" logger.error "Crawler data companies has error: #{e}"
end end
end end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
# Autoload # Crawler job
module Src class CrawlerJob < Crawler
# Crawler job
class CrawlerJob < Crawler
SIZE_LI = 8 SIZE_LI = 8
def crawl_link def crawl_link
...@@ -35,11 +33,11 @@ module Src ...@@ -35,11 +33,11 @@ module Src
parse_data.each do |path| parse_data.each do |path|
page = safe_link(path) page = safe_link(path)
if page.search('.item-blue .detail-box:nth-child(1) ul li:nth-child(1) p')[0].present? if page.search('.item-blue .detail-box:nth-child(1) ul li:nth-child(1) p')[0].present?
@data = Src::Interface::RedInterface.new(page).create_data @data = Interface::RedInterface.new(page).create_data
elsif page.search('section .template-200').text.present? elsif page.search('section .template-200').text.present?
@data = Src::Interface::BlueInterface.new(page).create_data @data = Interface::BlueInterface.new(page).create_data
elsif page.search('.DetailJobNew ul li').size == SIZE_LI && page.search('.right-col ul li').text.exclude?('Độ tuổi') elsif page.search('.DetailJobNew ul li').size == SIZE_LI && page.search('.right-col ul li').text.exclude?('Độ tuổi')
@data = Src::Interface::GreenInterface.new(page).create_data @data = Interface::GreenInterface.new(page).create_data
end end
add_data(@data) add_data(@data)
refresh_first_link refresh_first_link
...@@ -78,5 +76,4 @@ module Src ...@@ -78,5 +76,4 @@ module Src
job.cities << city job.cities << city
end end
end end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
# Inherience from base # Inherience from base
module Src module Interface
module Interface
class BlueInterface < Base::Base class BlueInterface < Base::Base
def fill_company_name def fill_company_name
page.search('.top-job .top-job-info .tit_company').text page.search('.top-job .top-job-info .tit_company').text
...@@ -41,5 +40,4 @@ module Src ...@@ -41,5 +40,4 @@ module Src
page.xpath('//ul//li[position()=7]/b').text page.xpath('//ul//li[position()=7]/b').text
end end
end end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
# ahihi # Green Interface
module Src module Interface
module Interface
class GreenInterface < Base::Base class GreenInterface < Base::Base
def fill_name def fill_name
page.search('.info-company h1').text page.search('.info-company h1').text
...@@ -45,5 +44,4 @@ module Src ...@@ -45,5 +44,4 @@ module Src
exist_experience? ? page.search('.DetailJobNew li:nth-child(5) span').text.strip : '' exist_experience? ? page.search('.DetailJobNew li:nth-child(5) span').text.strip : ''
end end
end end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
# Inherience from base # Inherience from base
module Src module Interface
module Interface
class RedInterface < Base::Base class RedInterface < Base::Base
end end
end
end end
...@@ -10,9 +10,9 @@ namespace :crawler do ...@@ -10,9 +10,9 @@ namespace :crawler do
company.address = 'Vui lòng xem trong mô tả công việc' company.address = 'Vui lòng xem trong mô tả công việc'
company.short_description = 'Vui lòng xem trong mô tả công việc' company.short_description = 'Vui lòng xem trong mô tả công việc'
end end
cw = Src::Crawler.new(NUMBER_LINK_WILL_BE_CRAWLER) cw = Crawler.new(NUMBER_LINK_WILL_BE_CRAWLER)
cw.craw_data_cities cw.craw_data_cities
cw.craw_data_companies cw.craw_data_companies
Src::CrawlerJob.new(NUMBER_LINK_WILL_BE_CRAWLER).craw_data_jobs CrawlerJob.new(NUMBER_LINK_WILL_BE_CRAWLER).craw_data_jobs
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment