Scrape LinkedIn Data Using R: A Step-by-Step Guide

Jason Gong
June 22, 2024

Set up R, inspect LinkedIn's HTML, and write your scraping script.

By the way, we're Bardeen, we build a free AI Agent for doing repetitive tasks.

If you're scraping LinkedIn data, you might find our LinkedIn Data Scraper useful. It automates data extraction, saving you time and effort.

Scraping data from LinkedIn using R is a powerful way to gather valuable insights for research, lead generation, or market analysis. In this step-by-step guide, we'll walk you through the process of setting up your R environment, understanding LinkedIn's HTML structure, writing and executing a scraping script, and cleaning and storing the scraped data. By the end of this guide, you'll have the knowledge and tools to effectively scrape data from LinkedIn while respecting legal and ethical considerations.


LinkedIn is a goldmine of valuable data for businesses, researchers, and marketers. By scraping data from LinkedIn, you can gather insights on industry trends, generate leads, and conduct market analysis. However, the process of scraping data from LinkedIn can be complex and time-consuming without the right tools and knowledge.

In this step-by-step guide, we'll show you how to harness the power of R to scrape data from LinkedIn efficiently and effectively. We'll cover everything from setting up your R environment and understanding LinkedIn's HTML structure to writing and executing a scraping script and cleaning and storing the scraped data.

Whether you're a beginner or an experienced R user, this guide will provide you with the knowledge and tools you need to successfully scrape data from LinkedIn posts while respecting legal and ethical considerations. So, let's dive in and unlock the potential of LinkedIn data for your research or business needs!

Preliminary Steps: Setting Up Your R Environment

Before you start scraping data from LinkedIn using R, you need to set up your R environment. This involves installing and loading the necessary packages, such as rvest, httr, and tidyverse.

To install these packages, run the following commands in your R console:

install.packages("rvest") install.packages("httr") install.packages("tidyverse")

Once the packages are installed, load them in your R script using:

library(rvest) library(httr) library(tidyverse)

Next, set up a proper working directory for storing your scripts and data outputs. This helps keep your project organized and makes it easier to locate files for further analysis. Use the setwd() function to set your working directory, like so:


Replace ~/path/to/your/project with the actual path to your project folder.

By completing these preliminary steps, you'll have a well-configured R environment ready for scraping data from LinkedIn.

Simplify your LinkedIn data extraction process and gain better insights by using Bardeen's LinkedIn company data playbook. Automate tasks with a single click.

Understanding LinkedIn's HTML Structure

To effectively scrape data from LinkedIn, you need to understand its HTML structure. Start by inspecting the page elements using your browser's developer tools. Right-click on the desired element and select "Inspect" to view the HTML code.

Look for unique identifiers such as classes, IDs, or specific attributes that can help you target the data you want to extract. Tools like SelectorGadget can assist in selecting the correct elements by simply clicking on them.

When inspecting LinkedIn's HTML, pay attention to:

  • Divs and spans that encapsulate specific content
  • Tables for data presented in a structured format
  • Lists (ordered or unordered) organizing information
  • Links and anchor tags for navigating between pages

Understand how CSS selectors work to target elements precisely:

  • Class selectors (.class) group elements with similar attributes
  • ID selectors (#id) identify unique elements
  • Element selectors (tagname) select by HTML tag
  • Attribute selectors ([attribute=value]) target based on attributes

Always respect LinkedIn's robots.txt file and terms of service to avoid legal issues. Adhere to ethical scraping practices and avoid excessive requests that may impact the site's performance.

Writing and Executing the Scraping Script

Once you have identified the necessary elements to scrape from LinkedIn, it's time to write the R script using the rvest package. Follow these step-by-step instructions:

  1. Load the required libraries:

library(rvest) library(httr) library(dplyr)

  1. Set up the LinkedIn URL and authentication:


  1. Extract specific data using CSS selectors:

name % html_node(".name") %>% html_text() title % html_node(".title") %>% html_text() location % html_node(".location") %>% html_text()

Repeat this process for other desired data points.

  1. Handle pagination by generating a sequence of URLs:

urls extract data from each page.

  1. Implement error handling using tryCatch():

tryCatch({ # Scraping code here }, error = function(e) { # Error handling code })This helps manage issues like connection failures or changes in page structure.

  1. Store the scraped data in a structured format:

profile_data Execute the script and verify the data has been collected correctly. Remember to respect LinkedIn's terms of service and avoid excessive requests that may lead to IP blocking.Save time and avoid hassle by using Bardeen's LinkedIn scraper playbook. Automate tasks with ease.Post-Scraping: Cleaning and Storing DataAfter scraping data from LinkedIn using R, the next crucial step is to clean and preprocess the data for efficient analysis. The dplyr package in R provides powerful functions to manipulate and transform the scraped data.Here are some tips for cleaning and organizing scraped LinkedIn data:

  1. Remove irrelevant or missing data using filter() and na.omit() functions.
  2. Rename columns for better readability with rename().
  3. Extract specific parts of text using regular expressions and mutate() with str_extract().
  4. Convert data types (e.g., character to numeric) using as.numeric(), as.Date(), etc.
  5. Aggregate data by grouping variables with group_by() and summarizing with summarise().

Once the data is cleaned, you can export it to various formats for storage and further analysis. Use write.csv() to save as a CSV file, writexl::write_xlsx() for Excel, or odbc::dbWriteTable() to store in a database.When working with scraped data, be mindful of ethical considerations and adhere to data privacy laws. Ensure you have permission to scrape and use the data, anonymize personal information if needed, and avoid overloading servers with excessive requests.By cleaning, structuring, and responsibly storing scraped LinkedIn data, you'll have a solid foundation for deriving valuable insights and conducting meaningful analyses in R. Simplify the data extraction process with Bardeen's automation tools to save time and effort.

Automate Your LinkedIn Data Scraping with Bardeen

While scraping data from LinkedIn using R is an effective method for gathering professional data, automating this process can significantly enhance efficiency and output. Bardeen offers powerful automation playbooks that streamline LinkedIn data scraping, eliminating manual tasks and providing structured data ready for analysis. Automating data extraction from LinkedIn not only saves time but also allows for the integration of data into various platforms seamlessly.

Here are some examples of how Bardeen can automate LinkedIn data scraping:

  1. Get data from a LinkedIn profile search: This playbook automates the extraction of professional data from LinkedIn profile searches, streamlining the process of gathering targeted professional information.
  2. Get data from the LinkedIn job page: Focuses on extracting job-related information from LinkedIn, making it easier for job seekers and recruiters to analyze the job market.
  3. Get data from a list of LinkedIn profile links in Google Sheets: This playbook enhances efficiency by automating the process of extracting data from a predefined list of LinkedIn profiles stored in Google Sheets.

Embrace Bardeen's automation capabilities to streamline your LinkedIn data scraping tasks. Download the app at and discover the power of automation.

Automate LinkedIn Data Extraction

Use Bardeen's LinkedIn Data Scraper to save time and gather insights effectively.

Get Bardeen free

Related frequently asked questions

How to Reference Another Sheet in Google Sheets: 3 Steps

Learn how to reference another sheet in Google Sheets using cell references, formulas, and conditional formatting to manage data efficiently.

Read more
Convert USD to CAD in Google Sheets: Easy Steps

Learn how to convert USD to CAD in Google Sheets using the GOOGLEFINANCE function for real-time exchange rates, ideal for financial analysis and budgeting.

Read more
Guide to Adding Contacts in Salesforce: 4 Methods

Discover how to add contacts in Salesforce individually, to campaigns, from reports, and in bulk. A step-by-step guide to efficient CRM management.

Read more
Effortlessly Link Google Form Responses to Sheets in 5 Steps

Learn to seamlessly import Google Form data to Sheets for real-time analysis and organization. Enhance data management with easy steps.

Read more
Easy Guide to Import Data into Google Sheets - 3 Methods

Discover how to import data into Google Sheets from websites, stock data, and PDFs. Learn about functions like IMPORTHTML and GOOGLEFINANCE.

Read more
Convert PDF to Excel in Google Sheets: 3 Easy Methods

Learn how to convert PDF to Excel in Google Sheets using Google Docs, CSV, or Parserr. Discover alternative solutions for efficient data extraction.

Read more
how does bardeen work?

Your proactive teammate — doing the busywork to save you time

Integrate your apps and websites

Use data and events in one app to automate another. Bardeen supports an increasing library of powerful integrations.

Perform tasks & actions

Bardeen completes tasks in apps and websites you use for work, so you don't have to - filling forms, sending messages, or even crafting detailed reports.

Combine it all to create workflows

Workflows are a series of actions triggered by you or a change in a connected app. They automate repetitive tasks you normally perform manually - saving you time.

get bardeen

Don't just connect your apps, automate them.

200,000+ users and counting use Bardeen to eliminate repetitive tasks

Effortless setup
AI powered workflows
Free to use
Reading time
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
By clicking “Accept”, you agree to the storing of cookies. View our Privacy Policy for more information.