Get company followers

Tags: #linkedin #company #followers #naas_drivers #automation #csv #content
Author: Florent Ravenel​
Last update: 2023-05-29 (Created: 2022-04-22)
This templates will get all followers from your LinkedIn company and save it into a CSV. Available columns :
  • FIRSTNAME : First name
  • LASTNAME : Last name
  • OCCUPATION : Text below the name in the profile page
  • PROFILE_PICTURE : Profile picture URL
  • PROFILE_URL : Profile URL
  • PROFILE_ID : LinkedIn profile id
  • PUBLIC_ID : LinkedIn public profile id
  • FOLLOWED_AT : Date of following company
  • DISTANCE : Distance between your profile
NB: Due to LinkedIn restriction, during the first execution, the follow at date will correspond to the 15 of the month. Then, the exact date will be retrieved for every new followers.
Disclaimer: This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by Linkedin or any of its affiliates or subsidiaries. It uses an independent and unofficial API. Use at your own risk.
This project violates Linkedin's User Agreement Section 8.2, and because of this, Linkedin may (and will) temporarily or permanently ban your account. We are not responsible for your account being banned.


Import libraries

from naas_drivers import linkedin
import pandas as pd
import naas

Setup LinkedIn

# Credentials
LI_AT = None or naas.secret.get(
JSESSIONID = None or naas.secret.get("JSESSIONID") # EXAMPLE ajax:8379907400220387585
# Company URL

Setup Variables

# Inputs
company_name = COMPANY_URL.strip().split("company/")[-1].split("/")[0]
csv_input = f"LINKEDIN_COMPANY_FOLLOWERS_{company_name}.csv"

Setup Naas scheduler

# Schedule your notebook everyday at 9:00 AM
naas.scheduler.add(cron="0 9 * * *")
# -> Uncomment the line below to remove your scheduler
# naas.scheduler.delete()


Get followers from company

# Get company followers from CSV stored in your local (Returns empty if CSV does not exist)
def get_company_followers(file_path):
df = pd.read_csv(file_path)
except FileNotFoundError as e:
# Empty dataframe returned
return pd.DataFrame()
return df
df_followers = get_company_followers(csv_input)

Update followers

def update_connections(df, file_path, key=None):
# Init output
df_update = pd.DataFrame()
# Init df posts is empty then return entire database
if len(df) > 0:
# If dataframe not empty, get last connections
profiles = df[key].unique()
start = 0
count = 1
while True:
tmp_new = linkedin.connect(LI_AT, JSESSIONID).company.get_followers(
start=start, count=count, limit=count
# Check if existing profile in each call
tmp_new = tmp_new[~tmp_new.PROFILE_ID.isin(profiles)]
df_update = pd.concat([df_update, tmp_new])
if len(tmp_new) == 0:
# Get more profile
start += count
print(f"-> New followers fetched: {len(df_update)}.")
df_update = linkedin.connect(LI_AT, JSESSIONID).company.get_followers(
count=100, limit=-1
# Concat data
df = pd.concat([df_update, df]).drop_duplicates(key, keep="first")
return df.reset_index(drop=True)
df_update = update_connections(df_followers, csv_input, key="PROFILE_ID")


Save dataframe in CSV

df_update.to_csv(csv_input, index=False)

Add dependency to production