-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgeneral_lk_utils.py
More file actions
70 lines (56 loc) · 1.86 KB
/
Copy pathgeneral_lk_utils.py
File metadata and controls
70 lines (56 loc) · 1.86 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
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import random
import json
import re
from urllib.parse import urlparse, parse_qs, urlencode, urlunparse
SELECT_CONTRACT_BUTTON_SELECTOR = "#main > div > div > div:nth-child(3) > form > div > ul > li:nth-child(1) > div > div.contract-list__item-buttons > button"
def get_lk_credentials(path="./lk_credentials.json"):
f = open(path)
data = json.load(f)
f.close()
return data
def enter_ids_on_lk_signin(driver, email, password):
time.sleep(2)
usernameInputElement = driver.find_element(By.ID, "username")
usernameInputElement.send_keys(email)
passwordInputElement = driver.find_element(By.ID, "password")
passwordInputElement.send_keys(password)
submitElement = driver.find_element(
By.CSS_SELECTOR,
"#organic-div > form > div.login__form_action_container > button",
)
time.sleep(1)
submitElement.click()
time.sleep(5)
def get_lk_url_from_sales_lk_url(url):
parsed = re.search("/lead/(.*?),", url, re.IGNORECASE)
if parsed:
return f"https://www.linkedin.com/in/{parsed.group(1)}"
return None
def select_contract_lk(driver):
contract_filter = driver.find_element(
By.CSS_SELECTOR, SELECT_CONTRACT_BUTTON_SELECTOR
)
contract_filter.click()
time.sleep(4)
return
def remove_url_parameter(url, param):
parsed_url = urlparse(url)
query_params = parse_qs(parsed_url.query)
if param in query_params:
del query_params[param]
new_query = urlencode(query_params, doseq=True)
new_url = urlunparse(
(
parsed_url.scheme,
parsed_url.netloc,
parsed_url.path,
parsed_url.params,
new_query,
parsed_url.fragment,
)
)
return new_url