-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedin_bot1.py
111 lines (66 loc) · 2.9 KB
/
linkedin_bot1.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
url = "https://www.linkedin.com/jobs/search"
def scrape_linkedin_jobs(job_name):
driver = webdriver.Firefox()
driver.get(url)
driver.implicitly_wait(3)
time.sleep(2)
search_input = driver.find_element(By.ID, "job-search-bar-keywords")
search_input.send_keys(job_name)
search_input.send_keys(Keys.RETURN)
time.sleep(2)
job_list_ul = driver.find_element(By.CSS_SELECTOR, "ul.jobs-search__results-list")
job_list_items = job_list_ul.find_elements(By.TAG_NAME, "li")
for job_item in job_list_items:
try:
job_title = job_item.find_element(By.CLASS_NAME, "base-search-card__title").text
print("Job Title:", job_title)
except Exception as e:
job_title = None
try:
company_name = job_item.find_element(By.CLASS_NAME, "hidden-nested-link").text
print("Company Name:", company_name)
except Exception as e:
company_name = None
try:
location = job_item.find_element(By.CLASS_NAME, "job-search-card__location").text
print("Location:", location)
except Exception as e:
location = None
try:
posted_time = job_item.find_element(By.CLASS_NAME, "job-search-card__listdate--new").text
print("Posted Time:", posted_time)
except Exception as e:
posted_time = None
try:
company_page_link = job_item.find_element(By.CLASS_NAME, "hidden-nested-link").get_attribute("href")
print("Company Page Link:", company_page_link)
except Exception as e:
company_page_link = None
try:
job_url = job_item.find_element(By.CLASS_NAME, "base-card__full-link").get_attribute("href")
print("Job URL:", job_url)
except Exception as e:
job_url = None
try:
benefits = job_item.find_element(By.CLASS_NAME, "job-posting-benefits__text").text
print("Benefits:", benefits)
except Exception as e:
benefits = None
#######
print("\n")
close_or_not = input("Enter 'yes' to close the driver or 'no' to keep it open : ")
if close_or_not == 'yes':
driver.quit()
elif close_or_not == 'no':
job_name = input("Enter the job name: ")
driver.quit()
scrape_linkedin_jobs(job_name)
else:
print("Bad input")
driver.quit()
job_name = input("Enter the job name: ")
scrape_linkedin_jobs(job_name)