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
ea11d8e6
Commit
ea11d8e6
authored
Jul 13, 2021
by
Mai Hoang Thai Ha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename namespace, use length instead of count,...
parent
423678ed
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
18 deletions
+17
-18
lib/tasks/web_crawler.rake
+17
-18
No files found.
lib/tasks/web_crawler.rake
View file @
ea11d8e6
...
...
@@ -2,18 +2,17 @@ require 'open-uri'
require
'csv'
require
'zip'
namespace
:
job
do
namespace
:
crawler
do
desc
'importjob'
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'
)
task
jobs: :environment
do
parsed_page
=
Nokogiri
::
HTML
(
HTTParty
.
get
(
'https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html'
).
body
)
jobs_item
=
parsed_page
.
css
(
'div.job-item .job_link'
)
(
0
..
jobs_item
.
length
-
1
).
each
do
|
item
|
job_link
=
jobs_item
[
item
].
attribute
(
'href'
).
text
job_page
=
Nokogiri
::
HTML
(
HTTParty
.
get
(
job_link
).
body
)
job_desc
=
job_page
.
css
(
'div.job-desc'
)
job_detail
=
job_page
.
css
(
'section.job-detail-content'
)
# title - company
title
=
job_desc
.
css
(
'h1.title'
).
text
company
=
job_desc
.
css
(
'a.job-company-name'
).
text
...
...
@@ -24,7 +23,7 @@ namespace :job do
# city, update_at, industry, type, salary, experience, level, expiration_date
update_at
,
industry
,
type
,
salary
,
experience
,
level
,
expiration_date
=
''
city
=
city_box
.
text
(
0
..
info_box_item
.
count
-
1
).
each
do
|
part
|
(
0
..
info_box_item
.
length
-
1
).
each
do
|
part
|
info
=
info_box_item
[
part
].
text
if
info
.
include?
(
key
=
'Ngày cập nhật'
)
update_at
=
info
.
squish
.
remove
(
key
).
strip
...
...
@@ -47,13 +46,13 @@ namespace :job do
benefit_list
=
[]
other_info_list
=
[]
benefits
=
job_detail
.
css
(
'ul.welfare-list li'
)
(
0
..
benefits
.
count
-
1
).
each
do
|
part
|
(
0
..
benefits
.
length
-
1
).
each
do
|
part
|
benefit
=
benefits
[
part
].
text
.
strip
benefit_list
<<
benefit
end
# description, requirement
description
,
requirement
=
''
(
0
..
job_detail_row
.
count
-
1
).
each
do
|
part
|
(
0
..
job_detail_row
.
length
-
1
).
each
do
|
part
|
job_detail_text
=
job_detail_row
[
part
].
text
if
job_detail_text
.
include?
(
'Mô tả Công việc'
)
description
=
job_detail_text
.
partition
(
'Mô tả Công việc'
).
last
.
squish
.
strip
...
...
@@ -63,7 +62,7 @@ namespace :job do
end
# benefit
other_info
=
job_detail
.
css
(
'div.content_fck ul li'
)
(
0
..
other_info
.
count
-
1
).
each
do
|
part
|
(
0
..
other_info
.
length
-
1
).
each
do
|
part
|
info
=
other_info
[
part
].
text
.
squish
.
strip
other_info_list
<<
info
end
...
...
@@ -89,11 +88,11 @@ namespace :job do
end
desc
'crawler industry form CareerBuilder'
task
web_industry_crawler
: :environment
do
task
industries
: :environment
do
parsed_page
||=
Nokogiri
::
HTML
(
HTTParty
.
get
(
'https://careerbuilder.vn/tim-viec-lam.html'
).
body
)
list_job
=
parsed_page
.
css
(
'div.list-of-working-positions ul.list-jobs li a'
)
industry_list
=
[]
(
0
..
list_job
.
count
-
1
).
each
do
|
part
|
(
0
..
list_job
.
length
-
1
).
each
do
|
part
|
industry
=
list_job
[
part
].
text
.
squish
.
strip
industry_list
<<
industry
end
...
...
@@ -101,11 +100,11 @@ namespace :job do
end
desc
'crawler city form CareerBuilder'
task
web_city_crawler
: :environment
do
task
cities
: :environment
do
parsed_page
||=
Nokogiri
::
HTML
(
HTTParty
.
get
(
'https://careerbuilder.vn/tim-viec-lam.html'
).
body
)
list_location
=
parsed_page
.
css
(
'div.main-jobs-by-location ul li'
)
city_list
=
[]
(
0
..
list_location
.
count
-
1
).
each
do
|
part
|
(
0
..
list_location
.
length
-
1
).
each
do
|
part
|
city_item
=
list_location
[
part
].
text
region
=
1
if
city_item
.
include?
(
key
=
'Việc làm tại'
)
...
...
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