-
-
Save brentonhouse/78fd32e22501b8929706b57427b77fa9 to your computer and use it in GitHub Desktop.
Backup relations from Linkedin
This file contains hidden or 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
""" | |
For work you need: copy as cUrl (bash) any of `GET` http-requests in Network tab (Chrome Dev-Tools): | |
- https://www.linkedin.com/voyager/api/relationships/dash/connections?decorationId=com.linkedin.voyager.dash.deco.web.mynetwork.ConnectionListWithProfile-15&count=40&q=search&sortType=RECENTLY_ADDED&start=40 | |
After paste press Enter twice :) | |
""" | |
import logging | |
import time | |
import requests | |
logging.basicConfig(level=logging.DEBUG) | |
logger = logging.getLogger(__name__) | |
logger.setLevel(logging.DEBUG) | |
def get_curl_cmd(): | |
curl_inputs = [] | |
while True: | |
curl_input = input() | |
if not curl_input: | |
break | |
curl_inputs.append(curl_input) | |
return curl_inputs | |
def build_request_data(curl_cmd): | |
base_url = curl_cmd[0].replace('curl \'', '')[:-3] | |
base_url = base_url.replace('&start=40', '&start=0').replace('&count=40', '&count=100') | |
logger.info('bsse_url: %s', base_url) | |
headers = {} | |
for header in curl_cmd[1:]: | |
if header == ' --compressed': | |
continue | |
header_data = header.split(': ') | |
header_data[0] = header_data[0][6:] | |
header_data[1] = header_data[1][:-3] | |
logger.info('header_data: %s', header_data) | |
headers.update({header_data[0]: header_data[1]}) | |
logger.info('headers: %s', headers) | |
return base_url, headers | |
curl_cmd = get_curl_cmd() | |
base_url, headers = build_request_data(curl_cmd) | |
logger.info(base_url, headers) | |
start = 0 | |
relations = [] | |
session = requests.Session() | |
session.headers.update(headers) | |
while True: | |
next_url = base_url.replace('&start=0', f'&start={start}') | |
logger.info('next_url: %s', next_url) | |
response_data = session.get(next_url).json() | |
logger.info('connections count: %s', len(response_data['included'])) | |
if not response_data['included']: | |
break | |
for relation in response_data['included']: | |
if 'publicIdentifier' in relation: | |
relations.append(relation['publicIdentifier']) | |
start += 100 | |
time.sleep(7) | |
relations = list(set(relations)) | |
logger.info(len(relations)) | |
for relation in relations: | |
logger.info(f'https://www.linkedin.com/in/{relation}/') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment