-
Notifications
You must be signed in to change notification settings - Fork 0
/
lkin.py
301 lines (256 loc) · 10.3 KB
/
lkin.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
from selenium import webdriver
from bs4 import BeautifulSoup
import getpass
import requests
from selenium.webdriver.common.keys import Keys
import pprint
import os
import datetime
import pandas as pd
import numpy as np
import re,glob
import csv
from pandas import ExcelWriter
from time import sleep
from subprocess import PIPE, run
import json
import glob
import pandas as pd
from pandas import ExcelWriter
import sqlite3
con= sqlite3.connect('info.db')
con.execute('''CREATE TABLE IF NOT EXISTS candidate(name text,
headline text,
company text,
school text,
location text,
summary text,
skills text,
publications text,
certifications text,
courses text,
projects text,
honors text,
languages text,
organizations text,
interests text,
experiences_title text,
experiences_company text,
experiences_date_range text,
experiences_location text,
experiences_description text)''')
con.commit()
cnt=1
columns = ['url','name','role', 'employer_name']
df_ = pd.DataFrame(columns=columns)
lsst=[]
search = str(input("Enter search key: "))
chk=1
chk = int(input("page count: "))
userid = str(input("Enter email address or number with country code: "))
password = getpass.getpass('Enter your password:')
chrome_path = './chromedriver'
driver = webdriver.Chrome(chrome_path)
driver.get("https://www.linkedin.com")
driver.implicitly_wait(6)
driver.find_element_by_xpath("""//*[@id="login-email"]""").send_keys(userid)
driver.find_element_by_xpath("""//*[@id="login-password"]""").send_keys(password)
driver.find_element_by_xpath("""//*[@id="login-submit"]""").click()
#driver.get("https://www.linkedin.com/in/sohini-mitra-582a87129/") #Enter any of your connection profile Link
cookies_list = driver.get_cookies()
cookies_dict = {}
for cookie in cookies_list:
cookies_dict[cookie['name']] = cookie['value']
li_at_id = cookies_dict.get('li_at')
search.strip()
search.replace(" ","%20")
#for i in range(1,pg+1)
pg=1
flg=True
while flg:
lnk = "https://www.linkedin.com/search/results/people/v2/?keywords="+search+"&origin=SWITCH_SEARCH_VERTICAL&page="+str(pg)
#driver.find_element_by_xpath("""//*[@id="ember942"]/input""").send_keys(search)
#sleep(0.5)
driver.get(lnk)
pg+=1
elem1 = driver.find_elements_by_xpath("//a[@class='search-result__result-link ember-view']")
driver.execute_script("window.scrollBy(0,1000)")
#sleep(3)
#driver.execute_script("window.scrollTo(0, document.body.scrollHeight+document.body.scrollHeight);")
elem2 = driver.find_elements_by_xpath("//a[@class='search-result__result-link ember-view']")
elems=elem1+elem2
all_elem=[]
for elem in elems:
if elem.get_attribute("href") not in all_elem:
all_elem.append(elem.get_attribute("href"))
print(all_elem)
for lnk in all_elem:
if cnt>chk:
flg=False
break
cnt+=1
try:
driver.get(lnk)
except:
continue
try:
name = driver.find_element_by_xpath("//*[@class='pv-top-card-section__name inline t-24 t-black t-normal']")
name=name.text
except:
name = "na"
try:
emp = driver.find_element_by_xpath("//*[@class='pv-top-card-v2-section__entity-name pv-top-card-v2-section__school-name text-align-left ml2 t-14 t-black t-bold lt-line-clamp lt-line-clamp--multi-line ember-view']")
emp=emp.text
except:
emp= "na"
try:
rol = driver.find_element_by_xpath("//*[@class='pv-top-card-section__headline mt1 t-18 t-black t-normal']")
rol=rol.text
except:
rol = "na"
fname = "C:/data/"+name+".json"
open(fname, 'a').close()
#proc = subprocess.Popen('cmd.exe', stdin = subprocess.PIPE, stdout = subprocess.PIPE)
#cmmd = 'scrapeli --url='+lnk+' -o "C:\Users\Simanta Sarkar\Desktop\lnk\cv\"+fname
#cmdd ="scrapeli --url="+lnk
#print(subprocess.Popen("scrapeli --url=", shell=True, stdout=subprocess.PIPE).stdout.read())
#os.system("scrapeli --url=https://www.linkedin.com/in/simanta-sarkar-67991914a")
#sleep(5)
#print(name ,"----------------cv parsed")
#os.system("start /wait cmd /c {scrapeli --url=https://www.linkedin.com/in/simanta-sarkar-67991914a -o 'C:\Users\Simanta Sarkar\Desktop\data.json'}")
command = ['scrapeli', '--url='+lnk,'--li_at='+str(li_at_id), '--output_file='+fname]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(result.returncode, result.stdout, result.stderr)
lst = [lnk,name,rol,emp]
lsst.append(lst)
lst = []
df_=pd.DataFrame(lsst,columns=['url','name','role', 'employer_name'])
# DF TO EXCEL
writer = ExcelWriter('PythonExport.xlsx')
df_.to_excel(writer,'Sheet5')
writer.save()
# DF TO CSV
df_.to_csv('PythonExport.csv', sep=',')
path =r'C:/data'
allFiles = glob.glob(path + "/*.json")
df = pd.DataFrame()
columns=['name','headline','company', 'school','location','summary','skills','publications','certifications','courses','projects','honors','languages','organizations','interests','experiences_title','experiences_company','experiences_date_range','experiences_location','experiences_description']
df_1 = pd.DataFrame(columns=columns)
lsst1=[]
for file_ in allFiles:
with open(file_, "r") as read_file:
data = json.load(read_file)
try:
name=data["personal_info"]["name"]
except:
name = ""
try:
headline=data["personal_info"]["headline"]
except:
headline=""
try:
company=data["personal_info"]["company"]
except:
company=""
try:
school=data["personal_info"]["school"]
except:
school=""
try:
location=data["personal_info"]["location"]
except:
location=""
try:
summary=data["personal_info"]["summary"]
except:
summary=""
e = data['experiences']['education']
for i in e:
print(i["name"])
print(i["degree"])
print(i["grades"])
print(i["field_of_study"])
print(i["date_range"])
e = data['experiences']['volunteering']
for i in e:
print(i["title"])
print(i["company"])
print(i["date_range"])
print(i["location"])
print(i["cause"])
print(i["description"])
try:
skil = data['skills']
skills=""
for i in skil:
skills+=", "+i["name"]
except:
skills=""
try:
pub = data['accomplishments']["publications"]
publications=" | ".join(pub)
except:
publications=""
try:
cer = data['accomplishments']["certifications"]
certifications=" | ".join(cer)
except:
certifications=""
try:
cou = data['accomplishments']["courses"]
courses=" | ".join(cou)
except:
courses=""
try:
pro = data['accomplishments']["projects"]
projects=" | ".join(pro)
except:
projects=""
try:
hon = data['accomplishments']["honors"]
honors=" | ".join(hon)
except:
honors=""
try:
lan = data['accomplishments']["languages"]
languages=" | ".join(lan)
except:
languages=""
try:
org = data['accomplishments']["organizations"]
organizations=" | ".join(org)
except:
organizations=""
try:
inte = data["interests"]
interests=" | ".join(inte)
except:
interests=""
j = data['experiences']['jobs']
with sqlite3.connect("info.db") as conn:
cur = conn.cursor()
for i in j:
experiences_title=i["title"]
experiences_company=i["company"]
experiences_date_range=i["date_range"]
experiences_location=i["location"]
experiences_description=i["description"]
cur.execute('''insert into candidate (name,headline,company, school,location,summary,skills,publications,certifications,courses,projects,honors,languages,organizations,interests,experiences_title,experiences_company,experiences_date_range,experiences_location,experiences_description)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', (name,headline,company, school,location,summary,skills,publications,certifications,courses,projects,honors,languages,organizations,interests,experiences_title,experiences_company,experiences_date_range,experiences_location,experiences_description))
con.commit()
lst = [name,headline,company, school,location,summary,skills,publications,certifications,courses,projects,honors,languages,organizations,interests,experiences_title,experiences_company,experiences_date_range,experiences_location,experiences_description]
lsst1.append(lst)
lst = []
df_1=pd.DataFrame(lsst1,columns=['name','headline','company', 'school','location','summary','skills','publications','certifications','courses','projects','honors','languages','organizations','interests','experiences_title','experiences_company','experiences_date_range','experiences_location','experiences_description'])
#df_1.append(df1)
# DF TO EXCEL
writer = ExcelWriter('PythonExport.xlsx')
df_1.to_excel(writer,'Sheet5')
writer.save()
# DF TO CSV
df_1.to_csv('PythonExportmrg.csv', sep=',')