Last active
June 29, 2023 13:35
-
-
Save n0sys/f8796b8cbdacafe3923aa9b3a7d4fe02 to your computer and use it in GitHub Desktop.
Python3 script to find out who unfollowed you on Linkedin :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import hashlib | |
import time | |
''' | |
1) $ curl "https://gist.githubusercontent.com/n0sys/f8796b8cbdacafe3923aa9b3a7d4fe02/raw/ea776055d0a08818bf7720b1da9fb4258ecbd04f/linkedin.py" -o linkedin.py | |
2) Login to linkedin then check your cookies: Get the values of cookies "li_at" and "JSESSIONID" then add them to the script below | |
3) $ python3 linkedin.py | |
''' | |
li_at_value = $li_at # Replace $li_at with the value of li_at cookie | |
csrf = $JSESSIONID # Replace $JSESSIONID with the value of JSESSIONID cookie (ex: csrf = "ajax:1111111111111111111") | |
connections_url = "https://www.linkedin.com/voyager/api/relationships/dash/connections?decorationId=com.linkedin.voyager.dash.deco.web.mynetwork.ConnectionListWithProfile-15&count=65&q=search&sortType=RECENTLY_ADDED&start=700" | |
followers_url = "https://www.linkedin.com/voyager/api/feed/richRecommendedEntities?count=1&q=followerRecommendations&start=0" | |
# headers | |
headers: dict = {'Csrf-Token':csrf} | |
# cookies | |
jar = requests.cookies.RequestsCookieJar() | |
jar.set('li_at', li_at_value, domain='.www.linkedin.com', path='/') | |
jar.set('JSESSIONID', csrf, domain='.www.linkedin.com', path='/') | |
# Get followers count | |
a = requests.get(followers_url, cookies=jar, headers= headers) | |
json_obj = json.loads(a.text) | |
total_followers = json_obj['paging']['total'] | |
print('Total followers: ', total_followers) | |
# Get connections count | |
url = "https://www.linkedin.com/voyager/api/search/dash/clusters?decorationId=com.linkedin.voyager.dash.deco.search.SearchClusterCollection-185&count=0&origin=Communities&q=all&query=(queryParameters:(resultType:List(CONNECTIONS)),flagshipSearchIntent:MYNETWORK_CURATION_HUB)&start=0" | |
a = requests.get(url, cookies=jar, headers= headers) | |
json_obj = json.loads(a.text) | |
total_connections = json_obj['paging']['total'] | |
print('Total connections: ', total_connections) | |
print("Fetching your connections...") | |
connect_hash: dict = {} | |
connections_counter = 0 | |
base_count = 400 | |
while connections_counter != total_connections: | |
if total_connections - connections_counter < base_count: | |
base_count = total_connections - connections_counter | |
connections_url = "https://www.linkedin.com/voyager/api/relationships/dash/connections?decorationId=com.linkedin.voyager.dash.deco.web.mynetwork.ConnectionListWithProfile-15&count="+str(base_count)+"&q=search&sortType=RECENTLY_ADDED&start="+str(connections_counter) | |
a = requests.get(connections_url, cookies=jar, headers= headers) | |
json_obj = json.loads(a.text) | |
for element in json_obj['elements']: | |
try: | |
user = element['connectedMemberResolutionResult']['firstName']+':'+element['connectedMemberResolutionResult']['lastName'] | |
connect_hash[hashlib.sha256(user.encode('utf8')).hexdigest()] = user | |
except: | |
pass | |
connections_counter += base_count | |
time.sleep(1) | |
print("Fetching your followers...") | |
follow_hash: dict = {} | |
followers_counter = 0 | |
base_count = 100 | |
while followers_counter != total_followers: | |
if total_followers - followers_counter < base_count: | |
base_count = total_followers - followers_counter | |
followers_url = "https://www.linkedin.com/voyager/api/feed/richRecommendedEntities?count="+str(base_count)+"&q=followerRecommendations&start="+str(followers_counter) | |
a = requests.get(followers_url, cookies=jar, headers= headers) | |
json_obj = json.loads(a.text) | |
for element in json_obj['elements']: | |
try: | |
user = element['recommendedEntity']['com.linkedin.voyager.feed.packageRecommendations.RecommendedMember']['miniProfile']['firstName']+':'+element['recommendedEntity']['com.linkedin.voyager.feed.packageRecommendations.RecommendedMember']['miniProfile']['lastName'] | |
follow_hash[hashlib.sha256(user.encode('utf8')).hexdigest()] = user | |
except: | |
pass | |
followers_counter += base_count | |
time.sleep(1) | |
if len(connect_hash) > len(follow_hash): | |
print("You have more connections than followers !\nLets see who unfollowed you :)") | |
for connection in connect_hash: | |
if connection not in follow_hash: | |
print('\t',connect_hash[connection]) | |
print("Sad for you :D") | |
elif len(connect_hash) < len(follow_hash): | |
print("You have more followers than connections !\nLets see who you unfollowed :)") | |
for follow in follow_hash: | |
if follow not in connect_hash: | |
print('\t',follow_hash[follow]) | |
print("Sad for them :D") | |
else: | |
# Check both cases here | |
print("You have equal number of followers and connections!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment