Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venjob_nth
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
3
Merge Requests
3
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
Ngô Trung Hưng
venjob_nth
Commits
bf921c4c
Commit
bf921c4c
authored
Aug 03, 2020
by
Ngô Trung Hưng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
..
parent
33c084b5
Pipeline
#763
failed with stages
in 0 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
13 additions
and
26 deletions
+13
-26
app/models/city.rb
+1
-0
app/models/company.rb
+1
-0
lib/src/base/base.rb
+4
-10
lib/src/crawler.rb
+1
-4
lib/src/crawler_job.rb
+1
-3
lib/src/interface/blue_interface.rb
+2
-4
lib/src/interface/green_interface.rb
+2
-4
lib/tasks/crawler.rake
+1
-1
No files found.
app/models/city.rb
View file @
bf921c4c
...
...
@@ -2,6 +2,7 @@
# Description/Explanation of Person class
class
City
<
ApplicationRecord
RANGE
=
69
has_many
:city_jobs
has_many
:jobs
,
through: :city_jobs
enum
area:
{
international:
0
,
domestic:
1
}
...
...
app/models/company.rb
View file @
bf921c4c
...
...
@@ -2,5 +2,6 @@
# Description/Explanation of Person class
class
Company
<
ApplicationRecord
COMPANY_SECURITY
=
1
has_many
:jobs
end
lib/src/base/base.rb
View file @
bf921c4c
...
...
@@ -6,8 +6,6 @@ require 'logger'
# Crawler data
class
Base
COMPANY_SECURITY
=
1
attr_accessor
:job
,
:page
def
initialize
(
page
)
...
...
@@ -54,7 +52,7 @@ class Base
end
def
fill_created_date
page
.
search
(
'.item-blue .detail-box:nth-child(1) ul li:nth-child(1) p'
)[
0
].
t
ext
page
.
search
(
'.item-blue .detail-box:nth-child(1) ul li:nth-child(1) p'
)[
0
].
t
ry
(
:text
)
end
def
fill_expiration_date
...
...
@@ -74,20 +72,16 @@ class Base
job
[
:description
]
=
page
.
search
(
'.tabs .tab-content .detail-row'
).
to_s
end
def
check
def
exist_experience?
noname
=
page
.
search
(
'//ul//li'
).
text
noname
.
include?
(
'Kinh nghiệm'
)
end
def
fill_lever
if
check
page
.
xpath
(
'//ul//li[position()=3]//p'
)[
1
].
text
.
strip
else
page
.
xpath
(
'//ul//li[position()=2]//p'
)[
1
].
text
end
exist_experience?
?
page
.
xpath
(
'//ul//li[position()=3]//p'
)[
1
].
text
.
strip
:
page
.
xpath
(
'//ul//li[position()=2]//p'
)[
1
].
text
end
def
fill_experience
check
?
page
.
xpath
(
'//ul//li[position()=2]//p'
)[
1
].
text
.
strip
:
''
exist_experience?
?
page
.
xpath
(
'//ul//li[position()=2]//p'
)[
1
].
text
.
strip
:
''
end
end
lib/src/crawler.rb
View file @
bf921c4c
...
...
@@ -4,9 +4,6 @@ require 'open-uri'
# Crawler data
class
Crawler
COMPANY_SECURITY
=
1
RANGE
=
69
attr_accessor
:number_link
def
initialize
(
number_link
)
...
...
@@ -48,7 +45,7 @@ class Crawler
page
=
Nokogiri
::
HTML
(
URI
.
open
(
'https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html'
))
locations
=
page
.
search
(
'#location option'
).
map
(
&
:text
)
locations
.
each_with_index
do
|
val
,
index
|
area
=
index
>
RANGE
?
City
.
areas
[
'international'
]
:
City
.
areas
[
'domestic'
]
area
=
index
>
City
::
RANGE
?
City
.
areas
[
'international'
]
:
City
.
areas
[
'domestic'
]
City
.
find_or_create_by
(
name:
val
)
{
|
city
|
city
.
area
=
area
}
end
end
...
...
lib/src/crawler_job.rb
View file @
bf921c4c
...
...
@@ -45,7 +45,7 @@ class CrawlerJob < Crawler
end
def
add_data
(
data
)
id_company
=
(
Company
.
find_by
name:
data
[
:company_name
]).
try
(
:id
)
||
COMPANY_SECURITY
id_company
=
(
Company
.
find_by
name:
data
[
:company_name
]).
try
(
:id
)
||
C
ompany
::
C
OMPANY_SECURITY
job
=
Job
.
create
(
name:
data
[
:name
],
company_id:
id_company
,
level:
data
[
:level
],
...
...
@@ -61,8 +61,6 @@ class CrawlerJob < Crawler
end
def
create_industry_relation
(
data
,
job
)
return
if
data
.
blank?
&&
id_job
.
blank?
industries
=
data
.
split
(
','
)
industries
.
each
do
|
val
|
val
.
gsub!
(
'&'
,
'&'
)
if
val
.
include?
(
'&'
)
...
...
lib/src/interface/blue_interface.rb
View file @
bf921c4c
...
...
@@ -10,8 +10,6 @@ class BlueInterface < Base
page
.
search
(
'.info-workplace .value a'
).
map
(
&
:text
).
join
(
','
)
end
def
fill_created_date
;
end
def
fill_expiration_date
page
.
xpath
(
'//ul//li[position()=4]//div'
).
text
end
...
...
@@ -28,13 +26,13 @@ class BlueInterface < Base
page
.
search
(
'.left-col'
).
to_s
end
def
check
def
exist_level?
noname
=
page
.
xpath
(
'//ul//li[position()=2]/b'
).
last
.
text
noname
.
include?
(
'Cấp bậc'
)
end
def
fill_lever
check
?
page
.
xpath
(
'//ul//li[position()=2]/div'
).
last
.
text
:
''
exist_level?
?
page
.
xpath
(
'//ul//li[position()=2]/div'
).
last
.
text
:
''
end
def
fill_experience
...
...
lib/src/interface/green_interface.rb
View file @
bf921c4c
...
...
@@ -14,8 +14,6 @@ class GreenInterface < Base
page
.
search
(
'.DetailJobNew ul li:nth-child(1) a'
).
text
end
def
fill_created_date
;
end
def
fill_expiration_date
page
.
xpath
(
'//ul//li[last()-1]//span'
).
children
[
1
].
text
end
...
...
@@ -36,12 +34,12 @@ class GreenInterface < Base
page
.
search
(
'.DetailJobNew li:nth-child(2) span'
).
text
.
strip
end
def
check_exp
def
exist_experience?
noname
=
page
.
search
(
'.DetailJobNew li span'
).
text
noname
.
include?
(
'Kinh nghiệm'
)
end
def
fill_experience
check_exp
?
page
.
search
(
'.DetailJobNew li:nth-child(5) span'
).
text
.
strip
:
''
exist_experience?
?
page
.
search
(
'.DetailJobNew li:nth-child(5) span'
).
text
.
strip
:
''
end
end
lib/tasks/crawler.rake
View file @
bf921c4c
...
...
@@ -5,7 +5,7 @@ require 'open-uri'
# rake task
namespace
:crawler
do
task
populate: :environment
do
NUMBER_LINK_WILL_BE_CRAWLER
=
100
NUMBER_LINK_WILL_BE_CRAWLER
=
5
Company
.
find_or_create_by
(
name:
'Bảo mật'
)
do
|
company
|
company
.
address
=
'Vui lòng xem trong mô tả công việc'
company
.
short_description
=
'Vui lòng xem trong mô tả công việc'
...
...
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