linkedin-topcompanies 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/linkedin-top-search +27 -0
- data/js/linkedin.js +23 -0
- data/lib/linkedin-topcompanies.rb +7 -2
- data/lib/linkedin-topcompanies/version.rb +1 -1
- metadata +5 -3
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "yaml"
|
3
|
+
require "linkedin-topcompanies"
|
4
|
+
|
5
|
+
if ARGV.length < 3
|
6
|
+
puts "usage: linkedin-top-search keywords postalcode industry"
|
7
|
+
exit
|
8
|
+
end
|
9
|
+
|
10
|
+
config = {}
|
11
|
+
if File.exists?("#{ENV['HOME']}/.linkedinrc")
|
12
|
+
config = YAML.load_file("#{ENV['HOME']}/.linkedinrc")
|
13
|
+
end
|
14
|
+
|
15
|
+
scraper = Linkedin::Topcompanies::LinkedInScraper.new(
|
16
|
+
:keywords => ARGV[0],
|
17
|
+
:postalcode => ARGV[1],
|
18
|
+
:industry => ARGV[2],
|
19
|
+
:linkedin_user => config["linkedin_user"],
|
20
|
+
:linkedin_password => config["linkedin_password"],
|
21
|
+
:debug => config["debug"]
|
22
|
+
)
|
23
|
+
|
24
|
+
result = scraper.run
|
25
|
+
result.each do |r|
|
26
|
+
puts "#{r["title"]} (#{r["count"]})"
|
27
|
+
end
|
data/js/linkedin.js
CHANGED
@@ -38,6 +38,11 @@ if (debug) {
|
|
38
38
|
console.info('LinkedIn user', linkedin_user);
|
39
39
|
}
|
40
40
|
|
41
|
+
casper.dieWithError = function(error, exitCode) {
|
42
|
+
exitCode = exitCode || 1;
|
43
|
+
this.die(JSON.stringify(error), exitCode);
|
44
|
+
}
|
45
|
+
|
41
46
|
casper.options.clientScripts = [jsPath + "/jquery.min.js"];
|
42
47
|
|
43
48
|
// performs login on LinkedIn page
|
@@ -52,6 +57,12 @@ casper.start('http://www.linkedin.com', function() {
|
|
52
57
|
// clicks Advanced people search
|
53
58
|
casper.then(function() {
|
54
59
|
if (debug) { console.info("Clicking advanced link..."); }
|
60
|
+
if (!this.getCurrentUrl().match("http://www.linkedin.com/home")) {
|
61
|
+
this.dieWithError({
|
62
|
+
message: "Login failed for user " + linkedin_user,
|
63
|
+
url: this.getCurrentUrl()
|
64
|
+
});
|
65
|
+
}
|
55
66
|
this.clickLabel('Advanced', 'a');
|
56
67
|
});
|
57
68
|
|
@@ -59,6 +70,18 @@ casper.then(function() {
|
|
59
70
|
// forms with proper attributes
|
60
71
|
casper.then(function() {
|
61
72
|
if (debug) { console.info("Submitting search..."); }
|
73
|
+
var count = this.evaluate(function(industry) {
|
74
|
+
return $("label:contains('" + industry + "')").length;
|
75
|
+
}, industry);
|
76
|
+
|
77
|
+
// when the industry is not found
|
78
|
+
if (count < 1) {
|
79
|
+
this.dieWithError({
|
80
|
+
message: "Industry '" + industry + "' not found",
|
81
|
+
url: this.getCurrentUrl()
|
82
|
+
});
|
83
|
+
}
|
84
|
+
|
62
85
|
this.clickLabel(industry, 'label');
|
63
86
|
this.fill('form[name=search]', {
|
64
87
|
keywords: keywords,
|
@@ -23,13 +23,18 @@ module Linkedin
|
|
23
23
|
credentials = "LINKEDIN_USER='#{linkedin_user}' LINKEDIN_PASSWORD='#{linkedin_password}'"
|
24
24
|
parameters = "KEYWORDS='#{keywords}' POSTALCODE='#{postalcode}' INDUSTRY='#{industry}'"
|
25
25
|
|
26
|
-
command = %Q(#{credentials} casperjs #{script} "#{path}")
|
26
|
+
command = %Q(#{credentials} #{parameters} casperjs #{script} "#{path}")
|
27
27
|
result = `#{command}`
|
28
28
|
|
29
29
|
if $?.exitstatus == 0
|
30
30
|
JSON.parse(result)
|
31
31
|
else
|
32
|
-
|
32
|
+
begin
|
33
|
+
error = JSON.parse(result.gsub(/\e\[[0-9]*(;[0-9]+)*m/, ""))
|
34
|
+
raise error["message"]
|
35
|
+
rescue JSON::ParserError
|
36
|
+
raise result
|
37
|
+
end
|
33
38
|
end
|
34
39
|
end
|
35
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linkedin-topcompanies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: casperjs
|
@@ -46,7 +46,8 @@ dependencies:
|
|
46
46
|
description: Given a keyword, an industry and a zipcode, retrieves top companies
|
47
47
|
email:
|
48
48
|
- felipe.coury@gmail.com
|
49
|
-
executables:
|
49
|
+
executables:
|
50
|
+
- linkedin-top-search
|
50
51
|
extensions: []
|
51
52
|
extra_rdoc_files: []
|
52
53
|
files:
|
@@ -55,6 +56,7 @@ files:
|
|
55
56
|
- LICENSE.txt
|
56
57
|
- README.md
|
57
58
|
- Rakefile
|
59
|
+
- bin/linkedin-top-search
|
58
60
|
- js/jquery.min.js
|
59
61
|
- js/linkedin.js
|
60
62
|
- lib/linkedin-topcompanies.rb
|