Commit cdd2eeb9 by Mai Hoang Thai Ha

fixed review part 2

parent a765decd
...@@ -50,38 +50,39 @@ namespace :crawler do ...@@ -50,38 +50,39 @@ namespace :crawler do
end end
# benefits, description, requirement, other_info # benefits, description, requirement, other_info
job_detail_rows = job_page.css('section.job-detail-content div.detail-row') job_detail_rows = job_page.css('section.job-detail-content div.detail-row')
benefits, description, requirement, other_info = [] benefits, description, requirement, other_info = ''
job_detail_rows.each do |detail_row| job_detail_rows.each do |detail_row|
detail_title = detail_row.css('.detail-title').text.strip detail_title = detail_row.css('.detail-title').text.strip
detail_content = detail_row.css(':not(h3.detail-title)')
case detail_title case detail_title
when 'Phúc lợi' when 'Phúc lợi'
benefits = detail_row.css(':not(h3.detail-title)').map(&:text).map(&:squish)[1..-1].reject(&:blank?).join('---') benefits = get_detail_text(detail_content)
when 'Mô tả Công việc' when 'Mô tả Công việc'
description = detail_row.css(':not(h3.detail-title)').map(&:text).map(&:squish)[1..-1].reject(&:blank?).join('---') description = get_detail_text(detail_content)
when 'Yêu Cầu Công Việc' when 'Yêu Cầu Công Việc'
requirement = detail_row.css(':not(h3.detail-title)').map(&:text).map(&:squish)[1..-1].reject(&:blank?).join('---') requirement = get_detail_text(detail_content)
when 'Thông tin khác' when 'Thông tin khác'
other_info = detail_row.css(':not(h3.detail-title)').map(&:text).map(&:squish)[1..-1].reject(&:blank?).join('---') other_info = get_detail_text(detail_content)
end end
end end
# Company # Company
company_name = job_page.css('div.job-desc a.job-company-name').text company_name = job_page.css('div.job-desc a.job-company-name').text
# Cities
cities = job_page.css('.job-detail-content .detail-box .map p a').map(&:text)
company_object = Company.find_or_create_by(name: company_name) company_object = Company.find_or_create_by(name: company_name)
job_object = Job.create({ title: job_title, job_object = Job.find_or_create_by({ title: job_title,
job_type: job_type, job_type: job_type,
salary: salary, salary: salary,
experience: experience, experience: experience,
position: level, position: level,
expiration_date: expiration_date, expiration_date: expiration_date,
description: description, description: description,
benefit: benefits, benefit: benefits,
requirement: requirement, requirement: requirement,
other_info: other_info, other_info: other_info,
company_id: company_object.id }) company_id: company_object.id })
industry_objects = industries.map { |industry| Industry.find_or_create_by(name: industry) } industry_objects = industries.map { |industry| Industry.find_or_create_by(name: industry) }
job_object.industries << industry_objects job_object.industries << industry_objects
# Cities
cities = job_page.css('.job-detail-content .detail-box .map p a').map(&:text)
city_objects = cities.map { |city| City.find_or_create_by(name: city) } city_objects = cities.map { |city| City.find_or_create_by(name: city) }
job_object.cities << city_objects job_object.cities << city_objects
rescue URI::InvalidURIError => e rescue URI::InvalidURIError => e
...@@ -112,15 +113,19 @@ namespace :crawler do ...@@ -112,15 +113,19 @@ namespace :crawler do
list_location = parsed_page.css('div.main-jobs-by-location ul li') list_location = parsed_page.css('div.main-jobs-by-location ul li')
list_location.each do |city| list_location.each do |city|
city_name = city.text city_name = city.text
region = City.regions[:international] region = :international
if city_name.include?('Việc làm tại') if city_name.include?('Việc làm tại')
city_name = city_name.remove('Việc làm tại').strip city_name = city_name.remove('Việc làm tại').strip
region = City.regions[:vietnam] region = :vietnam
end end
City.create( City.find_or_create_by(
name: city_name, name: city_name,
region: region region: region
) )
end end
end end
def get_detail_text(arr)
arr.map(&:text).map(&:squish)[1..-1].reject(&:blank?).join('---')
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