Tuesday, November 3, 2020

Use Python Selenium To Automate Chrome Driver & Like Posts On LinkedIn

If you're wanting a quick script to automatically like posts on LinkedIn, here is a snippet of code below  - contact me if you are interested in the zip file which includes the python automation application you can click on and simply enter the amount of times you want the script to scroll through and automatically like posts on LinkedIn - for review and testing only as: disclaimer - it's likely against LinkedIn's policy to automate anything like this and there could be consequences for real world use. 

Of course there are LinkedIn automation tools and extensions out there - like LinkedIn Helper - that are packaged as a fully ready tool to simply start using but imo highly focused python automation applications like this are better, and there are no monthly fees, just open and start...but it's all theory right, because we don't want violate LinkedIn's policy on using bots to manage our reputation do we.

Thoughts?

IDLE edit file

import pickle

import time

from selenium import webdriver

from selenium.webdriver.chrome.options import Options


# 0 - Default, 1 - Allow, 2 - Block

chrome_options = Options()

chrome_options.add_experimental_option("prefs", { "profile.default_content_setting_values.notifications": 2})

desired_cap = chrome_options.to_capabilities()

desired_cap.update({

  'browser_version': '75.0',

  'os': 'Windows',

  'os_version': '10'

})

print("*************************************")

run_scroll = input("How many times you want to Scroll: ")

print("*************************************")

run_scroll = int(run_scroll)


try:

    credential_list = []

    with open(r'login_credentials.txt', 'r') as f:

        x = f.readlines()


    for al in x:

        res = al.replace('\n', '')

        credential_list.append(res)

    # print(credential_list)

except:

    print("Check Credentials again in the text file, Text File Must be without Space ...")

# Load of the page you cant access without cookies, this one will go through

driver = webdriver.Chrome(chrome_options=chrome_options, executable_path="chromedriver.exe")

url = "https://www.linkedin.com/login"  # Linkedin URL

driver.get(url)  # GET URL

driver.maximize_window()  # Maximize window

driver.implicitly_wait(10)

time.sleep(4)


username = driver.find_element_by_xpath("//input[@id='username']").send_keys(credential_list[0])  # linkedin username

password = driver.find_element_by_xpath("//input[@id='password']").send_keys(credential_list[1])  # Linkedin password

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

driver.implicitly_wait(20)

time.sleep(5)


SCROLL_PAUSE_TIME = 3

count = 0

last_height = driver.execute_script("return document.documentElement.scrollHeight")

while True:

    # Scroll down to bottom

    driver.execute_script("window.scrollTo(0,document.documentElement.scrollHeight);")


    # Wait to load page

    time.sleep(SCROLL_PAUSE_TIME)


    # Calculate new scroll height and compare with last scroll height

    new_height = driver.execute_script("return document.documentElement.scrollHeight")

    count = count+1

    if count == run_scroll:

        break

    else:

        pass



likes_btn = driver.find_elements_by_xpath("//span[@class='artdeco-button__text react-button__text ']")

for x in likes_btn:

    res = driver.execute_script("arguments[0].click();", x)



No comments:

Post a Comment