Commit 31274088 by Mai Hoang Thai Ha

Fixed code style

parent f54f8365
# Web crawler
require 'open-uri'
require 'csv'
require 'zip'
namespace :job do
desc "import job"
desc 'importjob'
task web_job_import: :environment do
url = "https://careerbuilder.vn/vi/tim-viec-lam/nhan-vien-thiet-ke-thoi-trang.35B6D3AD.html"
url = 'https://careerbuilder.vn/vi/tim-viec-lam/nhan-vien-thiet-ke-thoi-trang.35B6D3AD.html'
unparsed_page = HTTParty.get(url)
parsed_page ||= Nokogiri::HTML(unparsed_page.body)
job_desc = parsed_page.css('div.job-desc')
job_detail = parsed_page.css('section.job-detail-content')
# title
title = job_desc.css('h1.title').text
company = job_desc.css('a.job-company-name').text
# info box
info_box = job_detail.css('div.detail-box')
info_box_item = info_box.css('ul li')
update_at, industry, type, salary, experience, level, expiration_date = ''
city = info_box.first.text.squish.remove("Địa điểm").strip
city = info_box.first.text.squish.remove('Địa điểm').strip
(0..info_box_item.count - 1).each do |part|
info = info_box_item[part].text
if info.include?(key = "Ngày cập nhật")
if info.include?(key = 'Ngày cập nhật')
update_at = info.squish.remove(key).strip
elsif info.include?(key = "Ngành nghề")
elsif info.include?(key = 'Ngành nghề')
industry = info.squish.remove(key).strip
elsif info.include?(key = "Hình thức")
elsif info.include?(key = 'Hình thức')
type = info.squish.remove(key).strip
elsif info.include?(key = "Lương")
elsif info.include?(key = 'Lương')
salary = info.squish.remove(key).strip
elsif info.include?(key = "Kinh nghiệm")
elsif info.include?(key = 'Kinh nghiệm')
experience = info.squish.remove(key).strip
elsif info.include?(key = "Cấp bậc")
elsif info.include?(key = 'Cấp bậc')
level = info.squish.remove(key).strip
elsif info.include?(key = "Hết hạn nộp")
elsif info.include?(key = 'Hết hạn nộp')
expiration_date = info.squish.remove(key).strip
end
end
# benefit
job_detail_row = job_detail.css('div.detail-row')
benefit_list = []
benefit_list = []
description_list = []
requirement_list = []
other_info_list = []
......@@ -51,19 +48,17 @@ namespace :job do
(0..benefits.count - 1).each do |part|
benefit = benefits[part].text.strip
benefit_list << benefit
end
end
# description - requirment
(0..job_detail_row.count - 1).each do |part|
job_detail_text = job_detail_row[part].text
if job_detail_text.include?("Mô tả Công việc")
if job_detail_text.include?('Mô tả Công việc')
descriptions = job_detail_row.css('p')
(0..descriptions.count - 1).each do |desc|
description = descriptions[desc].text.strip
description_list << description
end
elsif job_detail_text.include?("Yêu Cầu Công Việc")
elsif job_detail_text.include?('Yêu Cầu Công Việc')
requirements = job_detail_row.css('p')
(0..requirements.count - 1).each do |req|
requirement = requirements[req].text.strip
......@@ -76,8 +71,9 @@ namespace :job do
other_info = job_detail.css('div.content_fck ul li')
(0..other_info.count - 1).each do |part|
info = other_info[part].text.squish.strip
other_info_list << info
other_info_list << info
end
job = {
title: title,
company: company,
......@@ -95,6 +91,5 @@ namespace :job do
requirement: requirement_list,
other_info: other_info_list
}
byebug
end
end
\ No newline at end of file
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