Commit 7b814655 by julianbei

bugfixes

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