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
a765decd
Commit
a765decd
authored
Jul 27, 2021
by
Mai Hoang Thai Ha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed review
parent
9e051c4d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
22 deletions
+13
-22
app/models/city.rb
+1
-0
lib/tasks/web_crawler.rake
+12
-22
No files found.
app/models/city.rb
View file @
a765decd
class
City
<
ApplicationRecord
class
City
<
ApplicationRecord
has_and_belongs_to_many
:jobs
has_and_belongs_to_many
:jobs
enum
region:
{
vietnam:
0
,
international:
1
}
end
end
lib/tasks/web_crawler.rake
View file @
a765decd
...
@@ -79,17 +79,11 @@ namespace :crawler do
...
@@ -79,17 +79,11 @@ namespace :crawler do
benefit:
benefits
,
benefit:
benefits
,
requirement:
requirement
,
requirement:
requirement
,
other_info:
other_info
,
other_info:
other_info
,
company_id:
company_object
.
id
,
company_id:
company_object
.
id
})
created_at:
update_at
,
industry_objects
=
industries
.
map
{
|
industry
|
Industry
.
find_or_create_by
(
name:
industry
)
}
updated_at:
update_at
})
job_object
.
industries
<<
industry_objects
industries
.
map
do
|
industry
|
city_objects
=
cities
.
map
{
|
city
|
City
.
find_or_create_by
(
name:
city
)
}
industry_objects
=
Industry
.
find_or_create_by
(
name:
industry
)
job_object
.
cities
<<
city_objects
job_object
.
industries
<<
industry_objects
end
cities
.
map
do
|
city
|
city_objects
=
City
.
find_or_create_by
(
name:
city
)
job_object
.
cities
<<
city_objects
end
rescue
URI
::
InvalidURIError
=>
e
rescue
URI
::
InvalidURIError
=>
e
puts
"[Error]
#{
e
.
message
}
"
puts
"[Error]
#{
e
.
message
}
"
encode_url
=
CGI
.
escape
(
url
.
remove
(
'https://careerbuilder.vn/vi/tim-viec-lam/'
))
encode_url
=
CGI
.
escape
(
url
.
remove
(
'https://careerbuilder.vn/vi/tim-viec-lam/'
))
...
@@ -116,20 +110,16 @@ namespace :crawler do
...
@@ -116,20 +110,16 @@ namespace :crawler do
task
cities: :environment
do
task
cities: :environment
do
parsed_page
||=
Nokogiri
::
HTML
(
HTTParty
.
get
(
'https://careerbuilder.vn/tim-viec-lam.html'
).
body
)
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'
)
list_location
=
parsed_page
.
css
(
'div.main-jobs-by-location ul li'
)
list_location
.
each
do
|
part
|
list_location
.
each
do
|
city
|
city_name
=
part
.
text
city_name
=
city
.
text
region
=
1
region
=
City
.
regions
[
:international
]
if
city_name
.
include?
(
key
=
'Việc làm tại'
)
if
city_name
.
include?
(
'Việc làm tại'
)
city_name
=
city_name
.
remove
(
key
).
strip
city_name
=
city_name
.
remove
(
'Việc làm tại'
).
strip
region
=
0
region
=
City
.
regions
[
:vietnam
]
end
end
city
=
{
City
.
create
(
name:
city_name
,
name:
city_name
,
region:
region
region:
region
}
City
.
create
(
name:
city
[
:name
],
region:
city
[
:region
]
)
)
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