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
cdd2eeb9
Commit
cdd2eeb9
authored
Jul 27, 2021
by
Mai Hoang Thai Ha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed review part 2
parent
a765decd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
11 deletions
+16
-11
lib/tasks/web_crawler.rake
+16
-11
No files found.
lib/tasks/web_crawler.rake
View file @
cdd2eeb9
...
...
@@ -50,26 +50,25 @@ namespace :crawler do
end
# benefits, description, requirement, other_info
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
|
detail_title
=
detail_row
.
css
(
'.detail-title'
).
text
.
strip
detail_content
=
detail_row
.
css
(
':not(h3.detail-title)'
)
case
detail_title
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'
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'
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'
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
# Company
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
)
job_object
=
Job
.
create
({
title:
job_title
,
job_object
=
Job
.
find_or_create_by
({
title:
job_title
,
job_type:
job_type
,
salary:
salary
,
experience:
experience
,
...
...
@@ -82,6 +81,8 @@ namespace :crawler do
company_id:
company_object
.
id
})
industry_objects
=
industries
.
map
{
|
industry
|
Industry
.
find_or_create_by
(
name:
industry
)
}
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
)
}
job_object
.
cities
<<
city_objects
rescue
URI
::
InvalidURIError
=>
e
...
...
@@ -112,15 +113,19 @@ namespace :crawler do
list_location
=
parsed_page
.
css
(
'div.main-jobs-by-location ul li'
)
list_location
.
each
do
|
city
|
city_name
=
city
.
text
region
=
City
.
regions
[
:international
]
region
=
:international
if
city_name
.
include?
(
'Việc làm tại'
)
city_name
=
city_name
.
remove
(
'Việc làm tại'
).
strip
region
=
City
.
regions
[
:vietnam
]
region
=
:vietnam
end
City
.
create
(
City
.
find_or_create_by
(
name:
city_name
,
region:
region
)
end
end
def
get_detail_text
(
arr
)
arr
.
map
(
&
:text
).
map
(
&
:squish
)[
1
..-
1
].
reject
(
&
:blank?
).
join
(
'---'
)
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