-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbulk-message.py
96 lines (73 loc) · 2.69 KB
/
bulk-message.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# -*- coding: utf-8 -*-
from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options
options = Options()
options.headless = False
from bs4 import BeautifulSoup
import pandas
from datetime import datetime
import os
def login(driver):
flag=False
try:
driver.get('https://www.linkedin.com/uas/login')
time.sleep(4)
print("enter Username")
email=driver.find_element_by_id('username')
email.send_keys('futuresea713@gmail.com')
print("enter password")
passwd=driver.find_element_by_id('password')
passwd.send_keys('Future95713!')
print("Click on Signin")
driver.find_element_by_xpath('//button[@aria-label="Sign in"]').click()
time.sleep(2)
flag=True
pass
except:
pass
return flag
def search_name_get_url(driver,url):
try:
driver.get(url)
time.sleep(5)
list = driver.find_element_by_css_selector("ul.search-results__list.list-style-none")
mans = list.find_elements_by_tag_name('button')
for man in mans:
driver.execute_script("arguments[0].click();", man)
time.sleep(1)
try:
butt = driver.find_element_by_css_selector("button.mr1.artdeco-button.artdeco-button--muted.artdeco-button--3.artdeco-button--secondary.ember-view")
butt.click()
message = driver.find_element_by_id("custom-message")
message.send_keys("https://www.linkedin.com/pulse/credit-my-motto-hongbo-kim")
time.sleep(1)
div = driver.find_element_by_css_selector("div.artdeco-modal.artdeco-modal--layer-default.send-invite")
butts = div.find_elements_by_tag_name("button")
for idx, butt in enumerate(butts):
if idx == 2:
driver.execute_script("arguments[0].click();", butt)
time.sleep(1)
except:
pass
except Exception as e:
print(e)
pass
def main():
driver=''
try:
driver=webdriver.Chrome('chromedriver',options=options)
print("Login Process started")
if login(driver):
i = 25
while i < 100:
url = "https://www.linkedin.com/search/results/people/?facetGeoRegion=%5B%22us%3A0%22%5D&origin=FACETED_SEARCH&page=" + str(i)
search_name_get_url(driver,url)
i += 1
else:
print("Not able to login try again")
except Exception as e:
print(e)
pass
driver.close()
main()