Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VenJob
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mai Hoang Thai Ha
VenJob
Commits
e16f8904
Commit
e16f8904
authored
Jul 12, 2021
by
Mai Hoang Thai Ha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix description, requirement from array to string, crawler first page on CareerBuilder
parent
31274088
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
27 deletions
+22
-27
lib/tasks/web_crawler.rake
+22
-27
No files found.
lib/tasks/web_crawler.rake
View file @
e16f8904
# Web crawler
require
'open-uri'
require
'csv'
require
'zip'
...
...
@@ -6,20 +5,25 @@ require 'zip'
namespace
:job
do
desc
'importjob'
task
web_job_import: :environment
do
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
task
web_job_crawler: :environment
do
parsed_page
||=
Nokogiri
::
HTML
(
HTTParty
.
get
(
'https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html'
).
body
)
job_item
=
parsed_page
.
css
(
'div.job-item'
)
(
0
..
job_item
.
count
-
1
).
each
do
|
item
|
job_link
=
job_item
[
item
].
css
(
'div.title a'
).
attribute
(
'href'
).
text
unparsed_job_link
=
HTTParty
.
get
(
job_link
)
parsed_job_link
||=
Nokogiri
::
HTML
(
unparsed_job_link
.
body
)
job_desc
=
parsed_job_link
.
css
(
'div.job-desc'
)
job_detail
=
parsed_job_link
.
css
(
'section.job-detail-content'
)
# title - company
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'
)
city_box
=
info_box
.
css
(
'div.map a'
)
# city, update_at, industry, type, salary, experience, level, expiration_date
update_at
,
industry
,
type
,
salary
,
experience
,
level
,
expiration_date
=
''
city
=
info_box
.
first
.
text
.
squish
.
remove
(
'Địa điểm'
).
strip
city
=
city_box
.
text
(
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'
)
...
...
@@ -41,39 +45,28 @@ namespace :job do
# benefit
job_detail_row
=
job_detail
.
css
(
'div.detail-row'
)
benefit_list
=
[]
description_list
=
[]
requirement_list
=
[]
other_info_list
=
[]
benefits
=
job_detail
.
css
(
'ul.welfare-list li'
)
(
0
..
benefits
.
count
-
1
).
each
do
|
part
|
benefit
=
benefits
[
part
].
text
.
strip
benefit_list
<<
benefit
end
# description - requirment
# description, requirement
description
,
requirement
=
''
(
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'
)
descriptions
=
job_detail_row
.
css
(
'p'
)
(
0
..
descriptions
.
count
-
1
).
each
do
|
desc
|
description
=
descriptions
[
desc
].
text
.
strip
description_list
<<
description
end
description
=
job_detail_text
.
partition
(
'Mô tả Công việc'
).
last
.
squish
.
strip
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
requirement_list
<<
requirement
end
requirement
=
job_detail_text
.
partition
(
'Yêu Cầu Công Việc'
).
last
.
squish
.
strip
end
end
# other info
# benefit
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
end
job
=
{
title:
title
,
company:
company
,
...
...
@@ -87,9 +80,11 @@ namespace :job do
# position: position,
expiration_date:
expiration_date
,
benefit:
benefit_list
,
description:
description_list
,
requirement:
requirement_lis
t
,
description:
description
,
requirement:
requiremen
t
,
other_info:
other_info_list
}
puts
job
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment