fix crawler

parent 99daf536
Pipeline #1361 canceled with stages
in 0 seconds
class ChangeJobs < ActiveRecord::Migration[6.1] class ChangeJobs < ActiveRecord::Migration[6.1]
def up def up
change_column :jobs, :salary, :string change_column :jobs, :experience, :string
end end
def down def down
change_column :jobs, :salary, :integer change_column :jobs, :experience, :integer
end end
end end
...@@ -97,9 +97,9 @@ ActiveRecord::Schema.define(version: 2021_07_23_035105) do ...@@ -97,9 +97,9 @@ ActiveRecord::Schema.define(version: 2021_07_23_035105) do
t.text "requirement" t.text "requirement"
t.text "other_requirement" t.text "other_requirement"
t.string "salary" t.string "salary"
t.string "type" t.string "job_type"
t.string "level" t.string "level"
t.integer "experience" t.string "experience"
t.string "benefits" t.string "benefits"
t.datetime "expired_at" t.datetime "expired_at"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
......
...@@ -57,11 +57,11 @@ namespace :crawler do ...@@ -57,11 +57,11 @@ namespace :crawler do
salary, experience, type, level, expired_at = '' salary, experience, type, level, expired_at = ''
detail_content = detail_job.css('div.row div.detail-box.has-background ul li') detail_content = detail_job.css('div.row div.detail-box.has-background ul li')
detail_content.each do |content| detail_content.each do |content|
case content.css('strong').text case content.css('strong').text.strip
when 'Lương' when 'Lương'
salary = content.css('p').text salary = content.css('p').text
when 'Kinh nghiệm' when 'Kinh nghiệm'
experience = content.css('p').text experience = content.css('p').text.gsub('\r\n', '').strip
when 'Hình thức' when 'Hình thức'
type = content.css('p').text type = content.css('p').text
when 'Cấp bậc' when 'Cấp bậc'
...@@ -89,7 +89,7 @@ namespace :crawler do ...@@ -89,7 +89,7 @@ namespace :crawler do
title: title.text, title: title.text,
salary: salary, salary: salary,
experience: experience, experience: experience,
type: type, job_type: type,
level: level, level: level,
expired_at: expired_at, expired_at: expired_at,
benefits: benefits, benefits: benefits,
...@@ -103,19 +103,22 @@ namespace :crawler do ...@@ -103,19 +103,22 @@ namespace :crawler do
industries = detail_job.css('div.detail-box.has-background ul li p a') industries = detail_job.css('div.detail-box.has-background ul li p a')
industries.each do |industry| industries.each do |industry|
name = industry.text.squish name = industry.text.squish
job_industries << Industry.find_by(name: name) job_industry = Industry.find_by(name: name)
end next if job_industry.nil?
next if job_industries.nil?
job_industries << job_industry
end
job.industries << job_industries job.industries << job_industries
job_cities = [] job_cities = []
location = detail_job.css('div.map p a') location = detail_job.css('div.map p a')
location.each do |city| location.each do |city|
name = city.text name = city.text
job_cities << City.find_by(name: name) job_city = City.find_by(name: name)
next if job_city.nil?
job_cities << job_city
end end
next if job_cities.nil?
job.cities << job_cities job.cities << job_cities
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