Commit 7b814655 by julianbei

bugfixes

parent 351bee8a
...@@ -3,25 +3,24 @@ var LinkedInProfile = require('./index'); ...@@ -3,25 +3,24 @@ var LinkedInProfile = require('./index');
var url = 'https://de.linkedin.com/in/julian-beisenk%C3%B6tter-77038939'; var url = 'https://de.linkedin.com/in/julian-beisenk%C3%B6tter-77038939';
// standard usage // standard usage
LinkedInProfile(url) LinkedInProfile(url).then(function (profile) { // chain your logic
.then(function(profile){ // chain your logic
console.log(profile); console.log(profile);
}); });
// With links to similar profiles // With links to similar profiles
LinkedInProfile(url, true) LinkedInProfile(url, true)
.then(function(result){ .then(function (result) {
console.log(result.profile); // the requested profile console.log(result.profile); // the requested profile
console.log(result.links); // the featured profiles on the page console.log(result.links); // the featured profiles on the page
}); });
// usage with HTML // usage with HTML
var request = require('request-promise'); var request = require('request-promise');
request(url) // request with html output request(url) // request with html output
.then(function(html){ // promise chain .then(function (html) { // promise chain
return LinkedInProfile(html)// return the LinkedInProfile promise return LinkedInProfile(html);// return the LinkedInProfile promise
}) })
.then(function(profile){ // chain your logic .then(function (profile) { // chain your logic
console.log(profile); console.log(profile);
}); });
var baseAnalysis = function($, profile){ var baseAnalysis = function ($, profile) {
profile.url = $("link[rel='canonical']").attr("href"); profile.url = $("link[rel='canonical']").attr('href');
profile.contacts = $(".member-connections strong").text(); profile.contacts = $('.member-connections strong').text();
// Header Info // Header Info
profile.name = $("h1#name").text(); profile.name = $('h1#name').text();
profile.headline = $("p.headline.title").text(); profile.headline = $('p.headline.title').text();
profile.location = $("dl#demographics .descriptor.adr span.locality").text(); profile.location = $('dl#demographics .descriptor.adr span.locality').text();
profile.industry = $("dl#demographics dd:nth-child(4)").text(); profile.industry = $('dl#demographics dd:nth-child(4)').text();
// Picture // Picture
try { try {
profile.picture = $(".profile-picture img")[0].attributes['data-delayed-url']._nodeValue; profile.picture = $('.profile-picture img')[0].attributes['data-delayed-url']._nodeValue;
} catch (err) { } catch (err) {
profile.picture = ''; profile.picture = '';
} }
return profile; return profile;
} };
module.exports = baseAnalysis; module.exports = baseAnalysis;
var educationsAnalysis = function($, profile){ var educationsAnalysis = function ($, profile) {
// Education // Education
profile.educations = []; profile.educations = [];
$("#education .schools .school").each(function() { $('#education .schools .school').each(function () {
var schoolItem = $(this); var $schoolItem = $(this);
var school = { var school = {
school: schoolItem.find(".item-title").text(), school: $schoolItem.find('.item-title').text(),
course: schoolItem.find(".item-subtitle").text(), course: $schoolItem.find('.item-subtitle').text(),
from: schoolItem.find(".meta .date-range time:nth-child(1)").text(), from: $schoolItem.find('.meta .date-range time:nth-child(1)').text(),
to: schoolItem.find(".meta .date-range time:nth-child(2)").text(), to: $schoolItem.find('.meta .date-range time:nth-child(2)').text(),
description: schoolItem.find(".description p").text() description: $schoolItem.find('.description p').text(),
}; };
profile.educations.push(school); profile.educations.push(school);
}); });
return profile; return profile;
}; };
......
var featuredAnalysis = function($, profile){ var featuredAnalysis = function ($, profile) {
// Featured Info // Featured Info
profile.featured_current = $(".extra-info span.org").text(); profile.featured_current = $('.extra-info span.org').text();
profile.featured_past = $(".extra-info span.org").text(); profile.featured_past = $('.extra-info span.org').text();
profile.featured_education = $(".extra-info [data-section='educations'] td ol li").text(); profile.featured_education = $(".extra-info [data-section='educations'] td ol li").text();
return profile; return profile;
} };
module.exports = featuredAnalysis; module.exports = featuredAnalysis;
var linkedPeople = function($, links){ var linkedPeople = function ($, links) {
var links = []; var links = [];
$('.browse-map .profile-card a').each(function(){ $('.browse-map .profile-card a').each(function () {
var link = $(this).attr('href'); var link = $(this).attr('href');
links.push(link); links.push(link);
}); });
return links; return links;
}; };
......
var positionsAnalysis = function($, profile){ var positionsAnalysis = function ($, profile) {
// Experiences // Experiences
profile.positions = []; profile.positions = [];
$("#experience .positions .position").each(function() { $('#experience .positions .position').each(function () {
var positionItem = $(this); var $positionItem = $(this);
var position = { var position = {
position: positionItem.find(".item-title").text(), position: $positionItem.find('.item-title').text(),
companyName: positionItem.find(".item-subtitle").text(), companyName: $positionItem.find('.item-subtitle').text(),
from: positionItem.find(".meta .date-range time:nth-child(1)").text(), from: $positionItem.find('.meta .date-range time:nth-child(1)').text(),
to: positionItem.find(".meta .date-range time:nth-child(2)").text(), to: $positionItem.find('.meta .date-range time:nth-child(2)').text(),
locality: positionItem.find(".meta .location").text(), locality: $positionItem.find('.meta .location').text(),
description: positionItem.find(".description").text(), description: $positionItem.find('.description').text(),
current: (positionItem.attr('data-section') == "currentPositions") current: ($positionItem.attr('data-section') == 'currentPositionsDetails'),
}; };
profile.positions.push(position); profile.positions.push(position);
}); });
return profile; return profile;
}; };
......
var skillsAnalysis = function($, profile){ var skillsAnalysis = function ($, profile) {
// Skills // Skills
profile.skills = []; profile.skills = [];
$("#skills .pills li").each(function(){ $('#skills .pills li').each(function () {
var skill = $(this); var $skill = $(this);
var more = skill.hasClass('see-more'); var more = $skill.hasClass('see-more');
var less = skill.hasClass('see-less'); var less = $skill.hasClass('see-less');
if(!more && !less){ if (!more && !less) {
profile.skills.push({name: skill.text()}); profile.skills.push({ name: $skill.text() });
} }
}); });
return profile; return profile;
} };
module.exports = skillsAnalysis; module.exports = skillsAnalysis;
...@@ -2,7 +2,7 @@ var Profile = require('./profile'); ...@@ -2,7 +2,7 @@ var Profile = require('./profile');
var linkedPeople = require('./analyse-parts/linkedPeople'); var linkedPeople = require('./analyse-parts/linkedPeople');
var analyse = function (window, url) { var analyse = function (window, url) {
return new Promise(function(resolve, reject){ return new Promise(function (resolve, reject) {
try { try {
var $ = window.$; var $ = window.$;
var profile = new Profile($) var profile = new Profile($)
...@@ -15,9 +15,9 @@ var analyse = function (window, url) { ...@@ -15,9 +15,9 @@ var analyse = function (window, url) {
links = linkedPeople($); links = linkedPeople($);
resolve({profile: profile, links: links}) resolve({ profile: profile, links: links });
} catch (err) { } catch (err) {
reject(err) reject(err);
} }
}); });
}; };
......
// Scrape a linkedin profile for the public contents // Scrape a linkedin profile for the public contents
var Promise = require("bluebird"); var Promise = require('bluebird');
var analyser = require("./analyser"); var analyser = require('./analyser');
var retrieve = require("./retrieve"); var retrieve = require('./retrieve');
function getProfile(param, withlinks) { function getProfile(param, withlinks) {
return new Promise(function(resolve, reject){ return new Promise(function (resolve, reject) {
retrieve(param) // retrieve Profile retrieve(param) // retrieve Profile
.then(function(window){ .then(function (window) {
return analyser(window); // Analyse Page return analyser(window); // Analyse Page
}) })
.then(function(result){ .then(function (result) {
if(withlinks){ if (withlinks) {
resolve(result); // resolve to obj: {profile, links} resolve(result); // resolve to obj: {profile, links}
}else{ }else {
resolve(result.profile);// resolve to profile resolve(result.profile);// resolve to profile
} }
}).catch(function(err){ }).catch(function (err) {
reject(err); reject(err);
}); });
}); });
} }
module.exports = getProfile; module.exports = getProfile;
"use strict"; 'use strict';
var baseAnalysis = require('./analyse-parts/base'); var baseAnalysis = require('./analyse-parts/base');
var featuredAnalysis = require('./analyse-parts/featured'); var featuredAnalysis = require('./analyse-parts/featured');
...@@ -11,29 +11,29 @@ class Profile { ...@@ -11,29 +11,29 @@ class Profile {
this.$ = $; this.$ = $;
} }
base(){ base() {
return baseAnalysis(this.$, this); return baseAnalysis(this.$, this);
} }
featured(){ featured() {
return featuredAnalysis(this.$, this) return featuredAnalysis(this.$, this);
} }
positions(){ positions() {
return positionsAnalysis(this.$, this) return positionsAnalysis(this.$, this);
} }
skills(){ skills() {
return skillsAnalysis(this.$, this) return skillsAnalysis(this.$, this);
} }
educations(){ educations() {
return educationsAnalysis(this.$, this) return educationsAnalysis(this.$, this);
} }
clean(){ clean() {
delete this.$ delete this.$;
return this; return this;
} }
}; };
......
var jsdom = require("jsdom"); var jsdom = require('jsdom');
var retrieve = function (param) { var retrieve = function (param) {
return new Promise(function(resolve, reject){ return new Promise(function (resolve, reject) {
try { try {
var pattern = "^((https|http|ftp|rtsp|mms)?://)" var pattern = '^((https|http|ftp|rtsp|mms)?://)'
+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?"
+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" + '(([0-9]{1,3}\.){3}[0-9]{1,3}'
+ "|" + '|'
+ "([0-9a-z_!~*'()-]+\.)*" + "([0-9a-z_!~*'()-]+\.)*"
+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." + '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.'
+ "[a-z]{2,6})" + '[a-z]{2,6})'
+ "(:[0-9]{1,4})?" + '(:[0-9]{1,4})?'
+ "((/?)|" + '((/?)|'
+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
var regex = new RegExp(pattern); var regex = new RegExp(pattern);
var isURL = regex.test(param); var isURL = regex.test(param);
var callback = function(errors, window){ var callback = function (errors, window) {
if(errors){ if (errors) {
reject(errors); reject(errors);
}else{ }else {
resolve(window) resolve(window);
} }
}; };
if(!isURL){ if (!isURL) {
jsdom.env(param, jsdom.env(param,
["http://code.jquery.com/jquery.js"], ['http://code.jquery.com/jquery.js'],
callback callback
); );
}else{ }else {
jsdom.env({ url: param, jsdom.env({ url: param,
scripts: ["http://code.jquery.com/jquery.js"], scripts: ['http://code.jquery.com/jquery.js'],
done: callback done: callback,
}); });
} }
} catch (err) { } catch (err) {
reject(err) reject(err);
} }
}); });
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment