-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoConnect.py
More file actions
79 lines (66 loc) · 2.85 KB
/
Copy pathAutoConnect.py
File metadata and controls
79 lines (66 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
import time
from random import uniform
from sys import argv
from getpass import getuser, getpass
driver = webdriver.Chrome()
time.sleep(uniform(1, 3))
driver.maximize_window()
time.sleep(uniform(1, 3))
driver.get('https://linkedin.com')
time.sleep(uniform(1, 3))
driver.find_element_by_class_name("nav__button-secondary").click()
time.sleep(uniform(1, 3))
username = driver.find_element_by_xpath("//input[@name='session_key']")
password = driver.find_element_by_xpath("//input[@name='session_password']")
if "--noprompt" in argv:
username.send_keys(argv[2])
time.sleep(uniform(1, 3))
password.send_keys(argv[3])
link = argv[4]
else:
username.send_keys(input('LinkedIn email: '))
password.send_keys(getpass('LinkedIn password: '))
link = input("Paste link from search query: ")
time.sleep(uniform(1, 3))
driver.find_element_by_xpath("//button[@aria-label='Sign in']").click()
driver.get(link)
for i in range(0, 40):
print(i)
try:
connects = driver.find_elements_by_xpath("//button[contains(@aria-label, 'Connect with ')]")
# click connect for every connection
for element in connects:
time.sleep(uniform(1, 3))
try:
element.click()
except:
time.sleep(uniform(1, 3))
driver.implicitly_wait(uniform(1, 3))
try:
# cick send now in connection pane
element = driver.find_element_by_xpath("//button[contains(string(.), 'Send now')]")
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(element, 1, 1)
action.click()
action.perform()
time.sleep(uniform(1, 3))
driver.implicitly_wait(uniform(1, 3))
# dismiss connect pane if connection requires email
try:
driver.find_element_by_xpath("//button[@aria-label='Dismiss']").click()
except:
continue
except:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.find_element_by_xpath("//button[@aria-label='Next']").click()
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.find_element_by_xpath("//button[@aria-label='Next']").click()
time.sleep(uniform(1, 3))
except:
driver.implicitly_wait(uniform(1, 3))
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.find_element_by_xpath("//button[@aria-label='Next']").click()
time.sleep(uniform(1, 3))