├── parameters.py ├── README.md └── linkedIn.py /parameters.py: -------------------------------------------------------------------------------- 1 | file_name = 'connections.csv' 2 | linkedin_username = 'XXXXX@gmail.com' 3 | linkedin_password = 'XXXXXX' 4 | keywords = 'DevOps,Linux,Python,AWS' 5 | ignore_list = 'Person1,Person2' 6 | till_page = 10 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![](https://content.linkedin.com/content/dam/me/business/en-us/amp/brand-site/v2/bg/LI-Logo.svg.original.svg) 3 | # LinkedIn Networking 4 | 5 | Python code to automatically expand your LinkedIn network based on your interest 6 | 7 | 8 | 9 | 10 | 11 | ## Prerequisites 12 | 13 | Use the package manager [pip](https://pip.pypa.io/en/stable/) to install selenium. 14 | 15 | ```bash 16 | pip install selenium 17 | pip install webdriver-manager 18 | ``` 19 | 20 | ## How to use ? 21 | - Open parameters.py file and provide your email id, password, and keywords for search criteria. 22 | - Run `python linkedIn.py` 23 | 24 | 25 | ## Contribution 26 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 27 | 28 | 29 | ## Find me 30 | [![](https://img.shields.io/badge/Find%20Me-LinkedIn-blue?style=flat-square)](https://www.linkedin.com/in/akshaysiwal) [![](https://img.shields.io/badge/%20-Facebook-blue)](https://www.facebook.com/akshay.siwal.5) [![](https://img.shields.io/badge/-GitHub-lightgrey)](https://github.com/AkshaySiwal) 31 | -------------------------------------------------------------------------------- /linkedIn.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.chrome.service import Service 3 | from webdriver_manager.chrome import ChromeDriverManager 4 | from selenium.webdriver.common.keys import Keys 5 | from selenium.webdriver.common.by import By 6 | import parameters, csv, os.path, time 7 | 8 | 9 | # Functions 10 | def search_and_send_request(keywords, till_page, writer, ignore_list=[]): 11 | for page in range(1, till_page + 1): 12 | print('\nINFO: Checking on page %s' % (page)) 13 | query_url = 'https://www.linkedin.com/search/results/people/?keywords=' + keywords + '&origin=GLOBAL_SEARCH_HEADER&page=' + str(page) 14 | driver.get(query_url) 15 | time.sleep(5) 16 | html = driver.find_element(By.TAG_NAME, 'html') 17 | html.send_keys(Keys.END) 18 | time.sleep(5) 19 | linkedin_urls = driver.find_elements(By.CLASS_NAME, 'linked-area') 20 | print('INFO: %s connections found on page %s' % (len(linkedin_urls), page)) 21 | for index, result in enumerate(linkedin_urls, start=1): 22 | text = result.text.split('\n')[0] 23 | if text in ignore_list or text.strip() in ignore_list: 24 | print("%s ) IGNORED: %s" % (index, text)) 25 | continue 26 | connection_action = result.find_elements(By.CLASS_NAME, 'artdeco-button__text') 27 | if connection_action: 28 | connection = connection_action[0] 29 | else: 30 | print("%s ) CANT: %s" % (index, text)) 31 | continue 32 | if connection.text == 'Connect': 33 | try: 34 | coordinates = connection.location_once_scrolled_into_view # returns dict of X, Y coordinates 35 | driver.execute_script("window.scrollTo(%s, %s);" % (coordinates['x'], coordinates['y'])) 36 | time.sleep(5) 37 | connection.click() 38 | time.sleep(5) 39 | if driver.find_elements(By.CLASS_NAME, 'artdeco-button--primary')[0].is_enabled(): 40 | driver.find_elements(By.CLASS_NAME, 'artdeco-button--primary')[0].click() 41 | writer.writerow([text]) 42 | print("%s ) SENT: %s" % (index, text)) 43 | else: 44 | driver.find_elements(By.CLASS_NAME, 'artdeco-modal__dismiss')[0].click() 45 | print("%s ) CANT: %s" % (index, text)) 46 | except Exception as e: 47 | print('%s ) ERROR: %s' % (index, text)) 48 | time.sleep(5) 49 | elif connection.text == 'Pending': 50 | print("%s ) PENDING: %s" % (index, text)) 51 | else: 52 | if text: 53 | print("%s ) CANT: %s" % (index, text)) 54 | else: 55 | print("%s ) ERROR: You might have reached limit" % (index)) 56 | 57 | 58 | try: 59 | # Login 60 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) 61 | driver.get('https://www.linkedin.com/login') 62 | driver.find_element('id', 'username').send_keys(parameters.linkedin_username) 63 | driver.find_element('id', 'password').send_keys(parameters.linkedin_password) 64 | driver.find_element('xpath', '//*[@type="submit"]').click() 65 | time.sleep(10) 66 | # CSV file loging 67 | file_name = parameters.file_name 68 | file_exists = os.path.isfile(file_name) 69 | writer = csv.writer(open(file_name, 'a')) 70 | if not file_exists: writer.writerow(['Connection Summary']) 71 | ignore_list = parameters.ignore_list 72 | if ignore_list: 73 | ignore_list = [i.strip() for i in ignore_list.split(',') if i] 74 | else: 75 | ignore_list = [] 76 | # Search 77 | search_and_send_request(keywords=parameters.keywords, till_page=parameters.till_page, writer=writer, 78 | ignore_list=ignore_list) 79 | except KeyboardInterrupt: 80 | print("\n\nINFO: User Canceled\n") 81 | except Exception as e: 82 | print('ERROR: Unable to run, error - %s' % (e)) 83 | finally: 84 | # Close browser 85 | driver.quit() 86 | --------------------------------------------------------------------------------