linkedindata 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/linkedindata.rb +69 -0
- metadata +47 -0
data/lib/linkedindata.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'linkedin-scraper'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class LinkedinData
|
6
|
+
def initialize(input)
|
7
|
+
@input = input
|
8
|
+
@output = Array.new
|
9
|
+
end
|
10
|
+
|
11
|
+
# Searches for links on Google
|
12
|
+
def search
|
13
|
+
agent = Mechanize.new
|
14
|
+
gform = agent.get("http://google.com").form("f")
|
15
|
+
gform.q = "site:linkedin.com/pub " + @input
|
16
|
+
page = agent.submit(gform, gform.buttons.first)
|
17
|
+
examine(page)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Examines a search page
|
21
|
+
def examine(page)
|
22
|
+
startindex = 0
|
23
|
+
|
24
|
+
page.links.each do |link|
|
25
|
+
if (link.href.include? "linkedin.com") && (!link.href.include? "webcache") && (!link.href.include? "site:linkedin.com/pub+")
|
26
|
+
saveurl = link.href.split("?q=")
|
27
|
+
|
28
|
+
if saveurl[1]
|
29
|
+
url = saveurl[1].split("&")
|
30
|
+
scrape(url[0])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if (link.href.include? "&sa=N") && (link.href.include? "&start=")
|
35
|
+
url1 = link.href.split("&start=")
|
36
|
+
url2 = url1[1].split("&sa=N")
|
37
|
+
|
38
|
+
if url2[0].to_i < startindex
|
39
|
+
agent = Mechanize.new
|
40
|
+
examine(agent.get("http://google.com" + link.href))
|
41
|
+
else startindex = url2[0].to_i
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Scrapes profile and makes JSON
|
48
|
+
def scrape(url)
|
49
|
+
profile = Linkedin::Profile.get_profile(url)
|
50
|
+
|
51
|
+
if profile
|
52
|
+
profile.current_companies.each do |c|
|
53
|
+
c.merge!(:name => profile.first_name + " " + profile.last_name)
|
54
|
+
@output.push(c)
|
55
|
+
end
|
56
|
+
|
57
|
+
profile.past_companies.each do |c|
|
58
|
+
c.merge!(:name => profile.first_name + " " + profile.last_name)
|
59
|
+
@output.push(c)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Gets all data and returns in JSON
|
65
|
+
def getData
|
66
|
+
search
|
67
|
+
return @output.to_json
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: linkedindata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- M. C. McGrath
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Scrapes all LinkedIn profiles including terms you specify.
|
15
|
+
email: shidash@shidash.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/linkedindata.rb
|
21
|
+
homepage: https://github.com/Shidash/LinkedInData
|
22
|
+
licenses:
|
23
|
+
- GPL
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.23
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Get all LinkedIn profiles including terms you specify
|
46
|
+
test_files: []
|
47
|
+
has_rdoc:
|