LinkedIn Macro

I'm trying to parse out various fields from LinkedIn profiles. They look like this;

For this example we will use full name, I have tried getting it like this but it is not working. I have also tried the other class names in the above picture with no success.

%SafariJavaScript%document.getElementsByClassName("pv-top-card-section__body”).innerText

Hey @frontalspoof,

Please provide the URL to a specific profile, so we can test in common.

-Chris

I chose one at random; https://www.linkedin.com/in/sheryl-sandberg-5126652/

Any luck @ccstone

Maybe with a Perl script:

_[test] LinkedIn Parsing with Perl.kmmacros (14.2 KB)

Now that we have solved the issue I would like to know the reasoning behind not being able to do it with the simpler run javascript action, for learnings sake.

And even with the supplied example were just parsing from a copied variable not from the webpage directly so were not quite there yet.

Are you referring to the Perl script?

Hey @frontalspoof,

A lot of JavaScript objects are returned as arrays, and you have to properly reference the items you need.

You can use the AppleScript or pull the JavaScript statements out of it for KM actions.

------------------------------------------------------------------------------

set topCard to doJavaScriptInSafari("document.getElementById('top-card').innerHTML")
set theName to doJavaScriptInSafari("document.getElementsByClassName('fn')[0].textContent")
set theTitle to doJavaScriptInSafari("document.getElementsByClassName('title')[0].textContent")
set theLocality to doJavaScriptInSafari("document.getElementsByClassName('locality')[0].textContent")
set theIndustry to doJavaScriptInSafari("document.getElementsByClassName('industry')[0].textContent")

------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
on doJavaScriptInSafari(javascriptStr)
   try
      tell application "Safari" to do JavaScript javascriptStr in front document
   on error e
      error "Error in handler doJavaScriptInSafari() of library NLb!" & return & return & e
   end try
end doJavaScriptInSafari
------------------------------------------------------------------------------

-Chris

2 Likes

Hey Tom,

Mojo is not part of the default Perl install in macOS, so your macro doesn’t work out-of-the-box.

Is that Mojolicious?

http://search.cpan.org/~sri/Mojolicious-7.25/lib/Mojolicious.pm

It looks pretty useful.

So far I’ve only dabbled with Perl modules.

-Chris

I think it’s a dependency, yes.

This is true. I skipped that information because Perl is very kind and tells you verbosely which modules are missing :slightly_smiling_face:

But you are right, to be correct it should be mentioned beforehand.

I will try that out Chris, thanks very much for the assist here. I will let you know how it goes and share the final output so everyone can benefit.

1 Like