Comment on page

Extract content world cloud

Tags: #linkedin #worldcloud #content #analytics #dependency
Author: Florent Ravenel​
Last update: 2023-05-29 (Created: 2022-06-30)
Description: This notebook provides a way to extract content from LinkedIn and visualize it in a word cloud. To run this notebook, you must have already run LinkedIn_Get_profile_posts_stats.ipynb or LinkedIn_Get_company_posts_stats.ipynb to get your post stats in CSV.
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 wordcloud import WordCloud
!pip install wordcloud --user
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import pandas as pd

Setup Variables

# Input
csv_input = f"LINKEDIN_PROFILE_POSTS.csv" # CSV path with your posts stats generated with 'LinkedIn_Get_profile_posts_stats.ipynb' or 'LinkedIn_Get_company_posts_stats.ipynb'
# Outputs
image_output = f"{name_output}.png"

Setup Naas dependency

# -> Uncomment the line below to remove your dependency
# naas.dependency.delete()


Get your posts

Get posts feed from CSV stored in your local (Returns empty if CSV does not exist)
def read_csv(file_path):
df = pd.read_csv(file_path)
except FileNotFoundError as e:
# Empty dataframe returned
return pd.DataFrame()
return df
df_posts = read_csv(csv_input)
print("✅ Posts fetched:", len(df_posts))

Create trend dataframe

# Creating the text variable
text = " ".join(text for text in df_posts.astype(str).TEXT)
# Creating word_cloud with text as argument in .generate() method
word_cloud = WordCloud(
collocations=False, background_color="white", width=1200, height=600
%matplotlib inline
# Display the generated Word Cloud
plt.imshow(word_cloud, interpolation='bilinear')


Save and share your graph in image

# Save your image in PNG
# Share output with naas
# -> Uncomment the line below to remove your asset
# naas.asset.delete(image_output)