info@worthwebscraping.com
(+91) 79841 03276

How to Scrape LinkedIn Profiles without login using Python?

How to Scrape LinkedIn Profiles without login using Python?

Download Python Script

Send download link to:

LinkedIn is the best for connecting with business professionals. It contains global business information with millions of users. Most of business professionals use LinkedIn data to expand their business networks and company growth. So use LinkedIn data scraping and take benefits of data from it.

Today we will scrape the data from this particular LinkedIn profile and save the HTML page in a local folder using python. We will scrape data from this profile. Here the main thing is we will scrape the page without login. I want to save the LinkedIn profile page locally in this folder linkedin_page in D drive I created using python. For this, we have to install some packages. This is a website from where you can search and download the required packages.

open pypi.org website and here you can search and download required packages.

See complete code below or watch video for detailed explanation of LinkedIn data scraping:

Import libraries:

import requests
from time import sleep
from selenium import webdriver
import chromedriver_binary

Here we use selenium to send base request for getting cookie:

driver = webdriver.Chrome()
sleep(5)
driver.maximize_window()
sleep(5)
driver.get("https://www.linkedin.com/")
sleep(5)

Save cookie in variable:

cookies_dict = {}
for cookie in driver.get_cookies():
        cookies_dict[cookie['name']] = cookie['value']
        

driver.close()

Set headers & Send a get request:

resp = requests.get("https://www.linkedin.com/company/twitter",
                     cookies=cookies_dict,
                     headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
                              'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
                                                   'accept-encoding': 'gzip, deflate, br',
                                                   'accept-language': 'en-US,en;q=0.9',
                                                   'upgrade-insecure-requests': '1',
                                                   'scheme': 'https'})
        
html = resp.text


Save Profile page in Local Folder:

HtmlPath = "D:/linkedin_pages/1.html"
page_fun = open(HtmlPath,'w',encoding='utf-8')
page_fun.write(html)
page_fun.close()

you can parse the data from the response text we get. We can parse the data profile name, the number of employees, location, followers, about us section, website, Industry, company site, headquarters, type, when it was founded, locations. Without login, it will give us the four-employee name in case if you required it. It is just the parsing of data.

Now you understand how to send the request in LinkedIn. If you require multiple pages here, I explain one page so you can use it for a loop. You don’t have to open the browser multiple times. you have to send a request with a different URL because the cookie is already saved in the cookies_dict variable and we are applying it here. so, we don’t have to open it again and again only we have to change the LinkedIn profile URL.

Hope this tutorial is helpful to scrape LinkedIn public data. Apart from this we can scrape bulk data from LinkedIn. Once download our sample data Linkedin data extractor services.