Created
October 1, 2019 01:30
-
-
Save andreferraro/147ace0e1c117fdb5542ff61be6dcc9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
from getpass import getpass | |
import time | |
EXE_PATH = r'..\chromedriver.exe' | |
opts = Options() | |
opts.headless = False | |
login = input("Linked in Login: ") | |
password = getpass('Linked in Password: ') | |
occupationSearch = input("Insert the occupation that your looking for to connect: ") | |
messageContact = input("Check if this contact readed my message: ") | |
driver = webdriver.Chrome(executable_path=EXE_PATH, options=opts) | |
driver.set_window_size(1440, 900) | |
driver.get('https://www.linkedin.com/login') | |
time.sleep(3) | |
driver.find_element_by_id("username").send_keys(login) | |
driver.find_element_by_id("password").send_keys(password) | |
driver.find_element_by_xpath("//button[@type='submit']").click() | |
# adding all connections with Occupation equal CEO, CTO, Headhunter, Talent, Recruiter | |
time.sleep(5) | |
driver.get('https://www.linkedin.com/mynetwork/') | |
for i in range(10): | |
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") | |
time.sleep(3) | |
people = driver.find_elements_by_css_selector("section.discover-entity-type-card") | |
for person in people: | |
personName = person.find_elements_by_css_selector("span.discover-person-card__name")[0].text | |
personOccupation = person.find_elements_by_css_selector("span.discover-person-card__occupation")[0].text | |
if (occupationSearch.upper() in personOccupation.upper()): | |
print(f'Name: {personName}\nOccupation: {personOccupation}\n\n') | |
buttonInvite = person.find_elements_by_css_selector("button.artdeco-button--full")[0] | |
buttonInvite.send_keys(webdriver.common.keys.Keys.SPACE) | |
# getting all message threads | |
time.sleep(5) | |
driver.get('https://www.linkedin.com/messaging/') | |
for i in range(8): | |
messages = driver.find_elements_by_css_selector("ul.msg-conversations-container__conversations-list")[0] | |
driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', messages) | |
time.sleep(3) | |
conversations = driver.find_elements_by_css_selector("li.msg-conversation-listitem") | |
for conversation in conversations: | |
conversationLinks = conversation.find_elements_by_css_selector("a.msg-conversation-listitem__link") | |
if ( len(conversationLinks) > 0 ): | |
threadLink = conversationLinks[0].get_attribute("href") | |
participantName = conversationLinks[0].find_elements_by_css_selector("h3.msg-conversation-listitem__participant-names")[0].text | |
if ( messageContact.upper() == participantName.upper()): | |
print(f'Participant: {participantName}\nThread: {threadLink}\n\n') | |
break | |
driver.get(threadLink) | |
texts = driver.find_elements_by_css_selector("li.msg-s-message-list__event") | |
isReaded = False | |
for text in texts: | |
if (len(text.find_elements_by_css_selector("img.msg-s-event-listitem__seen-receipt-photo")) > 0): | |
isReaded = True | |
else: | |
isReaded = False | |
if ( isReaded == True ): | |
print('Your message was readed!') | |
else: | |
print('Your message was NOT readed!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment