

{"id":104015,"date":"2021-11-19T09:00:09","date_gmt":"2021-11-19T03:30:09","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=104015"},"modified":"2026-06-01T12:39:48","modified_gmt":"2026-06-01T07:09:48","slug":"python-linkedin-connections","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/","title":{"rendered":"Automate Linkedin Connections with Python"},"content":{"rendered":"<p>LinkedIn is a social platform for professional networking where people network with other people as well as exhibit their skills by demonstrating projects and sharing their accomplishments. Connecting with other people or Networking is a key use of LinkedIn since networking gives more room for knowledge sharing. Now we can see a way to automate linkedin connections using python<\/p>\n<h3>Python Automate LinkedIn connections project:<\/h3>\n<p>To automate LinkedIn connections using python, we make use of the library selenium.<\/p>\n<h3>Project Prerequisites:<\/h3>\n<p>The project requires certain libraries which can be installed using pip as follows:<\/p>\n<ul>\n<li>Selenium: pip install selenium<\/li>\n<\/ul>\n<p>Understanding the HTML layout of the websites will be of help to code.<\/p>\n<h3>Download Automating Linkedin Connections Project Code:<\/h3>\n<p>Please download the source code for automating linkedIn connections using python from the following link: <a href=\"https:\/\/drive.google.com\/file\/d\/1-dfstJafSOVXoeuq_l5PwDBs0d1cjjRl\/view?usp=drive_link\"><strong>Automate Linkedin Connections Project<\/strong><\/a><\/p>\n<h3>Project File Structure:<\/h3>\n<p>Below is the flow of the Automate Linkedin Connections project.<\/p>\n<p>1. Importing necessary library<\/p>\n<p>2. Declaring functions to login and connect with people<\/p>\n<p>3. Initialising the browser and calling functions<\/p>\n<h4>1. Importing libraries:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#DataFlair's Guide to Automating LinkedIn Connections using Python\r\n#Import libraries\r\nfrom selenium import webdriver<\/pre>\n<h4>Code Explanation:<\/h4>\n<ul>\n<li><strong>from selenium import webdriver:<\/strong> To automate the process, we use selenium. Selenium controls a web browser and performs the functions such as clicking on buttons or sending text to be filled in login forms and so on. To use a browser, we import webdriver from selenium. For further reading: selenium docs<\/li>\n<\/ul>\n<h4>2. Declaring functions to login and connect with people:<\/h4>\n<p><strong>NOTE:<\/strong> To webscrape and understand the given code snippets properly, open the website in another tab and put your mouse cursor at the desired area, which can be input areas, icons etc and right click. In the menu, you will find Inspect Element or just Inspect. That is how we obtain the details for the input fields discussed below.<\/p>\n<p><strong>NOTE 2:<\/strong> To find the path of any element, after selecting inspect, right click on the tag the console shows to you after you select inspect. From the menu, you can choose \u2018Copy Path\u2019 and it will display the various options.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def login_to_linkedin():\r\n#Find username\r\nUsername=browser.find_element_by_name(\"session_key\")\r\n#Send username details\r\nUsername.send_keys(\"enter username\")\r\n#Find password\r\npassword=browser.find_element_by_name(\"session_password\")\r\n#Send password details\r\npassword.send_keys(\"enter password\")\r\n#Submit button\r\nbrowser.find_element_by_xpath(\"\/\/button[@type='submit']\").click()<\/pre>\n<h4>Code Explanation:<\/h4>\n<ul>\n<li><strong>def login_to_linkedin():<\/strong> Function to login to linkedIn<\/li>\n<li><strong>Username=browser.find_element_by_name(&#8220;session_key&#8221;):<\/strong> The username input is given with the name \u2018session_key\u2019. Hence we give the same to place our control in the textbox.<\/li>\n<li><strong>Username.send_keys(&#8220;enter username&#8221;):<\/strong> Using send_keys, we send the credentials to the textbox so it can be placed in the input area.<br \/>\nThe same holds for password field<\/li>\n<li><strong>browser.find_element_by_xpath(&#8220;\/\/button[@type=&#8217;submit&#8217;]&#8221;).click():<\/strong> Now that we have sent the credentials to the login form, we now have to hit submit to login. To do that, we click on the \u2018sign in\u2019 button which is of type submit using xpath.<br \/>\nNote: find_element_by_name can be helpful when the input field or icon we want to select has a unique name that no other widget can share. On the other hand, xpath can be useful when the same HTML path is shared by many elements with few changes.<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def navigate_to_network_and_connect():\r\n#Navigate to the network page\r\nbrowser.find_element_by_xpath('\/\/*[@id=\"ember21\"]').click()\r\n#Cause a delay so it does not throw an error\r\nbrowser.implicitly_wait(5)\r\n#Select 'See All' browser.find_element_by_xpath('\/html\/body\/div[6]\/div[3]\/div\/div\/div\/div\/div[2]\/div\/div\/main\/ul\/li[1]\/div\/button\/span').click()\r\n#Obtain the number of items containing the same path\r\nelements = browser.find_elements_by_xpath('\/html\/body\/div[3]\/div\/div\/div[2]\/section\/div\/ul\/li')\r\nfor i in range(1,len(elements)+2):\r\n#Send connection request\r\nbrowser.find_element_by_xpath('\/html\/body\/div[3]\/div\/div\/div[2]\/section\/div\/ul\/li[{}]\/div\/section\/div[2]\/footer\/button\/span'.format(str(i))).click()\r\n#Connections send to 13 people at a time\r\nprint('Connection request sent to person {}'.format(str(i)))\r\n#Cause a time delay before progressing to next person\r\nbrowser.implicitly_wait(1)<\/pre>\n<h4>Code Explanation:<\/h4>\n<ul>\n<li><strong>def navigate_to_network_and_connect():<\/strong> To connect with people, we create this function<\/li>\n<li><strong>browser.find_element_by_xpath(&#8216;\/\/*[@id=&#8221;ember21&#8243;]&#8217;).click():<\/strong> To connect with people, we need to move to the page where the suggestions for connections are given.<\/li>\n<li><strong>browser.implicitly_wait(5):<\/strong> An error will pop up if selenium tries to access a HTML component before the webpage loads, thus terminating our program. To avoid that, we give a delay using this function for 5 seconds. An alternative is time.sleep(seconds) which requires time package.<br \/>\nbrowser.find_element_by_xpath().click(): The network page of linkedin contains people, pages and events. Thus to use only people, we select the option \u2018See All\u2019<\/li>\n<li><strong>elements:<\/strong> To get an idea of how many connections are present at a time, we find elements that contain a similar HTML path using find_elements_by_xpath.<\/li>\n<li><strong>for i in range(1,len(elements)+1):<\/strong> To provide connections request, we use a loop starting from 1 upto the last index, 12<\/li>\n<li><strong>browser.find_element_by_xpath().click():<\/strong> Click the connect button in the profile of various people<\/li>\n<li><strong>browser.implicitly_wait(1):<\/strong> A delay to wait for 1 second before connecting\/clicking on the connect button of another person\u2019s profile.<\/li>\n<\/ul>\n<h3>3. Initialising the browser and calling functions:<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#Open the webbrowser and use it for autonomous control\r\nbrowser = webdriver.Firefox(executable_path='\/home\/deepika\/Downloads\/internship\/instagram\/geckodriver')\r\n#Open the URL in the opened webbrowser\r\nbrowser.get('https:\/\/www.linkedin.com\/login?fromSignIn=true&amp;trk=guest_homepage-basic_nav-header-signin')\r\n#Start using the functions after a delay\r\nbrowser.implicitly_wait(5)\r\n#Call all the functions in order based on webpages\r\nlogin_to_linkedin()\r\nnavigate_to_network_and_connect()<\/pre>\n<h4>Code explanation:<\/h4>\n<ul>\n<li><strong>browser = webdriver.Firefox():<\/strong> To automate sending connections using python, we need a browser with autonomous control. Thus we use firefox with the executable_path set to the .exe file which is nothing but the driver for the web browser. Firefox uses Geckodriver and chrome uses its own driver. Check for version compatibility when using the browsers and their driver files<\/li>\n<li><strong>browser.get(&#8216;\u2019):<\/strong> In the browser we have opened autonomously, we now make it open the login page of linkedin.<\/li>\n<li><strong>browser.implicitly_wait(5):<\/strong> Before calling the functions, the browser must load with the website. So we give a delay using implicitly_wait(). This is analogous to time.sleep()<\/li>\n<li><strong>login_to_linkedin(), navigate_to_network_and_connect():<\/strong> Call functions in the order of the webpages.<\/li>\n<\/ul>\n<h4>Python Automate Linkedin Connections Output:<\/h4>\n<p>Run the python linkedin bot program and view your output<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/python-automate-linkedin-connections-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-104246\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/python-automate-linkedin-connections-output.webp\" alt=\"python automate linkedin connections output\" width=\"1366\" height=\"723\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/python-automate-linkedin-connections-output.webp 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/python-automate-linkedin-connections-output-768x406.webp 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>Thus we found a way to automate sending of connection requests to people on linkedin using python. This project is a great introduction to web scraping and is ideal for a beginner to try.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2549,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1-dfstJafSOVXoeuq_l5PwDBs0d1cjjRl\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20260601070955\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1-dfstJafSOVXoeuq_l5PwDBs0d1cjjRl\\\/view?usp=drive_link&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-06-01 11:44:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-06 19:41:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-13 11:59:57&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-13 11:59:57&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>LinkedIn is a social platform for professional networking where people network with other people as well as exhibit their skills by demonstrating projects and sharing their accomplishments. Connecting with other people or Networking is&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":104247,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[25803,25801,25878,21082,25802],"class_list":["post-104015","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-automate-linkedin-connections-using-python","tag-automating-linkedin-connections-project","tag-python-linkedin-connections","tag-python-project","tag-python-project-to-automate-linkedin-connections"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Automate Linkedin Connections with Python - DataFlair<\/title>\n<meta name=\"description\" content=\"Develop project to automate LinkedIn connections using python selenium library in easy step by step manner.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automate Linkedin Connections with Python - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Develop project to automate LinkedIn connections using python selenium library in easy step by step manner.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-19T03:30:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T07:09:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/automate-linkedin-connections-python.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Automate Linkedin Connections with Python - DataFlair","description":"Develop project to automate LinkedIn connections using python selenium library in easy step by step manner.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/","og_locale":"en_US","og_type":"article","og_title":"Automate Linkedin Connections with Python - DataFlair","og_description":"Develop project to automate LinkedIn connections using python selenium library in easy step by step manner.","og_url":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2021-11-19T03:30:09+00:00","article_modified_time":"2026-06-01T07:09:48+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/automate-linkedin-connections-python.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Automate Linkedin Connections with Python","datePublished":"2021-11-19T03:30:09+00:00","dateModified":"2026-06-01T07:09:48+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/"},"wordCount":877,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/automate-linkedin-connections-python.webp","keywords":["Automate Linkedin Connections Using Python","Automating linkedin connections project","python linkedin connections","Python project","Python Project to automate linkedin connections"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/","url":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/","name":"Automate Linkedin Connections with Python - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/automate-linkedin-connections-python.webp","datePublished":"2021-11-19T03:30:09+00:00","dateModified":"2026-06-01T07:09:48+00:00","description":"Develop project to automate LinkedIn connections using python selenium library in easy step by step manner.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/automate-linkedin-connections-python.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/automate-linkedin-connections-python.webp","width":1200,"height":628},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-linkedin-connections\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Automate Linkedin Connections with Python"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/104015","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=104015"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/104015\/revisions"}],"predecessor-version":[{"id":148626,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/104015\/revisions\/148626"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/104247"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=104015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=104015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=104015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}