Python Tutorial 24: Linkedin Scraper & Bot, Automate Adding Connections and Messaging

Linkedin, which is the professional networking platform, recently announced that the China version of Linkedin will sunset later this year. It’s due to a significantly more challenging operating environment and greater compliance requirement. It will launch the global standalone platform called InJobs in China. But the platform will not include a social media feed or the ability to share posts or articles. It’s what it is. Linkedin business networking is still very valuable to users, no matter whether Chinese need to use VPN to login their profiles, or inJob still has the feature of people search.

python tutorial

1-on-1 communication is critical in B2B marketing, which is different with massive consumer market campaigns. After all, B2B deals before closing have more considerations than just buying a piece of iPhone case. Frankly, it doesn’t have many high quality business network platforms globally. Before you have plenty of qualified 1st party data applied to emails, social media and advertising, Linkedin must be one of the battlegrounds your B2B business line has to take up.

In this Python Tutorial, I would walk you through how to automate increasing specific target connections, and activate the automatic messagings. It’s for the purpose to start the conversation with your target business account. By the end of this Python Tutorial, you can master the basic rules of Linkedin connections and tips and tricks to use this bot and scraper. And mostly important, you can start automating instead of what you are repeatedly doing everyday.

Linkedin Connection Rules and Account Creation Tips

Each linkedin user can have at most 30k connections and unlimit followers. Apart from recruitment and job search purposes, people usually leverage the connection to build business networks and blast business related messagings.

To any new users, she or he can go to search a company or a name with or without some filters. Basically here is the place to add new connections and messaging to your 1st connections.

python tutorial

Messaging to 2nd connection and 3rd connection requires signing up to Linkedin premium plans. So in this Python Tutorial, it mainly talks about how to automate messagings to 1st connections.

Personally there are two tips and tricks. First, please sign up for a new account and put it as a dummy account instead of using your real personal account. It’s because Linkedin on and off investigates the robot account. It’s for avoiding your personal one that might be suspended.

Secondly, please add some friends with a certain amount of linkedin connections before automating networking. It’s better to build connections with more than 5000. It’s because Linkedin doesn’t grant access to your profile and you can’t see the 2nd or 3rd connections button if your account hasn’t any connections.

Python Tutorial – People Search URL Parameters

Adding new connections is the first step of this Python bot script. Adding people from different companies are different with what company name or brand name keywords you input into the section.

For example, here is the URL for searching people from Furbo which is the well-known brand of pet camera device. In the script, apart from the path, the keyword parameter can change for different results. You can add furbo, tesla, microsoft, etc. What’s more, you can go to the 2nd page, 3rd page, and more by changing the page parameter.


python tutorial

For specifically searching your 1st connection using keywords, you need to add one parameter “network=%5B%22F%22%5D” in the URL.

For example,

Add New Connections Automatically

First thing first, we need to find the connect button element and the path. Luckily, Linkedin assigns this button with the button element. It’s easy to write this line of code. But things you need to be aware of are the buttons with different messages. You don’t need to click all the buttons. So here is the codes that only click those button named in connect

all_buttons = driver.find_elements_by_tag_name("button")
connect_buttons = [btn for btn in all_buttons if btn.text == "Connect"]

Then, things are not just a one-click button. There are 3 steps broken down in this journey, which are “click, send and close”.

driver.execute_script("arguments[0].click();", btn)
send = driver.find_element_by_xpath("//button[@aria-label='Send now']")
driver.execute_script("arguments[0].click();", send)
close = driver.find_element_by_xpath("//button[@aria-label='Dismiss']")
driver.execute_script("arguments[0].click();", close)

You might find that there are some blockers in the Linkedin scraping process. Basically there are three types of blockers

– Blank elements
– Inactive elements
– Element not interactable exceptions

When adding new connections, you would come across sometimes the Javascript pop-up or snippets stopping your scraping. So for resolving this and making the scraping go smoothly, you need to add execute_script and arguments[0]. It is your way of accessing the first argument to the anonymous function.

Python Tutorial – Sending 1st Connection Messages Automatically

Regarding automatic messages, you must have a specific company or brand communication objective. So the keyword here should be the brand or company name in your 1st connections.

First thing first, it’s different with adding new connections. Now you need to click the button named in message

all_buttons = driver.find_elements_by_tag_name("button")
message_buttons = [btn for btn in all_buttons if btn.text == "Message"]

Then, creating a for loop is necessary as you would repeat to click and send the same messages. If you need to visit more than 1 page, you also need to create one more for loop above this level

for contacts in range(0,len(message_buttons))

driver.execute_script("arguments[0].click();", message_buttons[contacts])

One key step here is to add this xpath, because you have to click the message window before you type any messages. To activate this section and paragraph section, you need to add this script.

main_div = driver.find_element_by_xpath("//div[starts-with(@class, 'msg-form__msg-content-container')]")

Last but not least, you paste the message to the conversation window and box, and click the submit button and close button. Basically one automatic messaging is done until here.

paragraphs = driver.find_elements_by_tag_name("p")

message = "Hi Louis, Sorry for bothering you, I just came across your product on Amazon USA and see it's very popular. I am wondering if you're interested in expanding the sales from China, let me know thank you!"


submit = driver.find_element_by_xpath("//button[@type='submit']").click()

close_button = driver.find_element_by_xpath("//button[starts-with(@data-control-name, 'overlay.close_conversation_window')]")

driver.execute_script("arguments[0].click();", close_button)

I would walk you through how to customise the name and opening in the next Python Tutorial chapter.

python tutorial

Full Python Script of Linkedin Scraper and Bot

If you would like to have the full version of the Python Script of Amazon Product Price Tracker, please subscribe to our newsletter by adding the message Python Tutorial 24. We would send you the script immediately to your mailbox.

I hope you enjoy reading Python Tutorial 24: Linkedin Scraper & Bot, Automate Adding Connections and Messagings. If you did, please support us by doing one of the things listed below, because it always helps out our channel.

  • Support my channel through PayPal (
  • Subscribe to my channel and turn on the notification bell Easy2Digital Youtube channel.
  • Follow and like my page Easy2Digital Facebook page
  • Share the article to your social network with the hashtag #easy2digital
  • Buy products with Easy2Digital 10% OFF Discount code (Easy2DigitalNewBuyers2021)
  • You sign up for our weekly newsletter to receive Easy2Digital latest articles, videos, and discount code on Buyfromlo products and digital software
  • Subscribe to our monthly membership through Patreon to enjoy exclusive benefits (

Leave a Reply

Your email address will not be published. Required fields are marked *