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
'open-uri'
require
'csv'
require
'csv'
require
'zip'
require
'zip'
...
@@ -6,20 +5,25 @@ require 'zip'
...
@@ -6,20 +5,25 @@ require 'zip'
namespace
:job
do
namespace
:job
do
desc
'importjob'
desc
'importjob'
task
web_job_import: :environment
do
task
web_job_crawler: :environment
do
url
=
'https://careerbuilder.vn/vi/tim-viec-lam/nhan-vien-thiet-ke-thoi-trang.35B6D3AD.html'
parsed_page
||=
Nokogiri
::
HTML
(
HTTParty
.
get
(
'https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html'
).
body
)
unparsed_page
=
HTTParty
.
get
(
url
)
job_item
=
parsed_page
.
css
(
'div.job-item'
)
parsed_page
||=
Nokogiri
::
HTML
(
unparsed_page
.
body
)
(
0
..
job_item
.
count
-
1
).
each
do
|
item
|
job_desc
=
parsed_page
.
css
(
'div.job-desc'
)
job_link
=
job_item
[
item
].
css
(
'div.title a'
).
attribute
(
'href'
).
text
job_detail
=
parsed_page
.
css
(
'section.job-detail-content'
)
unparsed_job_link
=
HTTParty
.
get
(
job_link
)
# title
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
title
=
job_desc
.
css
(
'h1.title'
).
text
company
=
job_desc
.
css
(
'a.job-company-name'
).
text
company
=
job_desc
.
css
(
'a.job-company-name'
).
text
# info box
# info box
info_box
=
job_detail
.
css
(
'div.detail-box'
)
info_box
=
job_detail
.
css
(
'div.detail-box'
)
info_box_item
=
info_box
.
css
(
'ul li'
)
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
=
''
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
|
(
0
..
info_box_item
.
count
-
1
).
each
do
|
part
|
info
=
info_box_item
[
part
].
text
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'
)
...
@@ -41,39 +45,28 @@ namespace :job do
...
@@ -41,39 +45,28 @@ namespace :job do
# benefit
# benefit
job_detail_row
=
job_detail
.
css
(
'div.detail-row'
)
job_detail_row
=
job_detail
.
css
(
'div.detail-row'
)
benefit_list
=
[]
benefit_list
=
[]
description_list
=
[]
requirement_list
=
[]
other_info_list
=
[]
other_info_list
=
[]
benefits
=
job_detail
.
css
(
'ul.welfare-list li'
)
benefits
=
job_detail
.
css
(
'ul.welfare-list li'
)
(
0
..
benefits
.
count
-
1
).
each
do
|
part
|
(
0
..
benefits
.
count
-
1
).
each
do
|
part
|
benefit
=
benefits
[
part
].
text
.
strip
benefit
=
benefits
[
part
].
text
.
strip
benefit_list
<<
benefit
benefit_list
<<
benefit
end
end
# description - requirment
# description, requirement
description
,
requirement
=
''
(
0
..
job_detail_row
.
count
-
1
).
each
do
|
part
|
(
0
..
job_detail_row
.
count
-
1
).
each
do
|
part
|
job_detail_text
=
job_detail_row
[
part
].
text
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'
)
description
=
job_detail_text
.
partition
(
'Mô tả Công việc'
).
last
.
squish
.
strip
(
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'
)
requirement
=
job_detail_text
.
partition
(
'Yêu Cầu Công Việc'
).
last
.
squish
.
strip
(
0
..
requirements
.
count
-
1
).
each
do
|
req
|
requirement
=
requirements
[
req
].
text
.
strip
requirement_list
<<
requirement
end
end
end
end
end
# benefit
# other info
other_info
=
job_detail
.
css
(
'div.content_fck ul li'
)
other_info
=
job_detail
.
css
(
'div.content_fck ul li'
)
(
0
..
other_info
.
count
-
1
).
each
do
|
part
|
(
0
..
other_info
.
count
-
1
).
each
do
|
part
|
info
=
other_info
[
part
].
text
.
squish
.
strip
info
=
other_info
[
part
].
text
.
squish
.
strip
other_info_list
<<
info
other_info_list
<<
info
end
end
job
=
{
job
=
{
title:
title
,
title:
title
,
company:
company
,
company:
company
,
...
@@ -87,9 +80,11 @@ namespace :job do
...
@@ -87,9 +80,11 @@ namespace :job do
# position: position,
# position: position,
expiration_date:
expiration_date
,
expiration_date:
expiration_date
,
benefit:
benefit_list
,
benefit:
benefit_list
,
description:
description_list
,
description:
description
,
requirement:
requirement_lis
t
,
requirement:
requiremen
t
,
other_info:
other_info_list
other_info:
other_info_list
}
}
puts
job
end
end
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