|
| 1 | +import getpass |
| 2 | +from selenium import webdriver |
| 3 | +from webdriver_manager.chrome import ChromeDriverManager |
| 4 | +from selenium.webdriver.common.keys import Keys |
| 5 | +from selenium.webdriver.support.ui import WebDriverWait |
| 6 | +from selenium.webdriver.support import expected_conditions as EC |
| 7 | +from selenium.webdriver.common.by import By |
| 8 | +from time import sleep |
| 9 | + |
| 10 | +# Xpaths |
| 11 | +xLinkedin = { |
| 12 | + 'xEmail': '//input[@name="session_key"]', |
| 13 | + 'xPass': '//input[@name="session_password"]', |
| 14 | + 'xLogin': '//button[contains(.,"Sign in")]', |
| 15 | + 'xProfile': '//div[@data-control-name="identity_welcome_message"]', |
| 16 | + 'xCertName': '//input[@placeholder="Ex: Microsoft certified network associate security"]', |
| 17 | + 'xCertOrg': '//input[@placeholder="Ex: Microsoft"]', |
| 18 | + 'xCredId': '//input[@id="single-line-text-form-component-profileEditFormElement-CERTIFICATION-profileCertification-ACoAADI-i-oBZzsiExXBGep7oC4p5cgLkd4v7kE-1-licenseNumber"]', |
| 19 | + 'xCredUrl': '//input[@id="single-line-text-form-component-profileEditFormElement-CERTIFICATION-profileCertification-ACoAADI-i-oBZzsiExXBGep7oC4p5cgLkd4v7kE-1-url"]', |
| 20 | + 'xSave': '//button[contains(.,"Save")]' |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +class LinkedIn: |
| 25 | + def __init__(self, email, password): |
| 26 | + self.email = email |
| 27 | + self.password = password |
| 28 | + |
| 29 | + def login(self): |
| 30 | + emailField = driver.find_element_by_xpath(xLinkedin['xEmail']) |
| 31 | + emailField.send_keys(self.email) |
| 32 | + passwordField = driver.find_element_by_xpath(xLinkedin['xPass']) |
| 33 | + passwordField.send_keys(self.password) |
| 34 | + |
| 35 | + submitBtn = driver.find_element_by_xpath(xLinkedin['xLogin']) |
| 36 | + submitBtn.click() |
| 37 | + WebDriverWait(driver, 10).until(EC.presence_of_element_located( |
| 38 | + (By.XPATH, xLinkedin['xProfile']))).click() |
| 39 | + |
| 40 | + def addCertData(self, name, org, credId, credUrl): |
| 41 | + sleep(5) |
| 42 | + currentUrl = driver.current_url |
| 43 | + driver.get(currentUrl+'edit/forms/certification/new/') |
| 44 | + nameInput = WebDriverWait(driver, 10).until(EC.presence_of_element_located( |
| 45 | + (By.XPATH, xLinkedin['xCertName']))) |
| 46 | + nameInput.send_keys(name) |
| 47 | + sleep(1) |
| 48 | + orgInput = driver.find_element_by_xpath(xLinkedin['xCertOrg']) |
| 49 | + orgInput.send_keys(org) |
| 50 | + sleep(3) |
| 51 | + orgInput.send_keys(Keys.ARROW_DOWN + Keys.ENTER) |
| 52 | + credIdInput = driver.find_element_by_xpath(xLinkedin['xCredId']) |
| 53 | + credIdInput.send_keys(credId) |
| 54 | + credUrlInput = driver.find_element_by_xpath(xLinkedin['xCredUrl']) |
| 55 | + credUrlInput.send_keys(credUrl) |
| 56 | + driver.find_element_by_xpath(xLinkedin['xSave']).click() |
| 57 | + |
| 58 | + |
| 59 | +if __name__ == "__main__": |
| 60 | + # Get LinkedIn credentials |
| 61 | + email = input('Enter your linkedin email: ') |
| 62 | + password = getpass.getpass('Password: ') |
| 63 | + |
| 64 | + # Chrome environment setup |
| 65 | + opt = webdriver.ChromeOptions() |
| 66 | + opt.add_argument('--disable-gpu') |
| 67 | + opt.add_argument('--headless') |
| 68 | + driver = webdriver.Chrome(ChromeDriverManager().install(), options=opt) |
| 69 | + driver.get('https://linkedin.com') |
| 70 | + |
| 71 | + linkedIn = LinkedIn(email, password) |
| 72 | + linkedIn.login() |
| 73 | + |
| 74 | + # Add certifications to linkedin |
| 75 | + while True: |
| 76 | + name = input('Enter course name[nothing to cancel]: ') |
| 77 | + if name == '': |
| 78 | + break |
| 79 | + courseUrl = input(f'Enter course url for the course[\'{name}\']: ') |
| 80 | + org = input('Enter the name of the issuing organistion: ') |
| 81 | + courseId = courseUrl.split('/')[-1] |
| 82 | + linkedIn.addCertData(name=name, org=org, |
| 83 | + credId=courseId, credUrl=courseUrl) |
| 84 | + print(f'Added: {name}') |
| 85 | + name = '' |
| 86 | + print('Completed!') |
| 87 | + driver.close() |
0 commit comments