-
Notifications
You must be signed in to change notification settings - Fork 0
/
lkin1.py
251 lines (213 loc) · 8.29 KB
/
lkin1.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
# -*- 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
columns = ['url','name','role', 'employer_name']
df_ = pd.DataFrame(columns=columns)
lsst=[]
search = str(input("Enter search key: "))
pg = 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
search.strip()
search.replace(" ","%20")
for i in range(1,pg+1):
lnk = "https://www.linkedin.com/search/results/people/v2/?keywords="+search+"&origin=SWITCH_SEARCH_VERTICAL&page="+str(i)
#driver.find_element_by_xpath("""//*[@id="ember942"]/input""").send_keys(search)
sleep(0.5)
driver.get(lnk)
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:
try:
driver.get(lnk)
driver.add_cookie({'domain':None,'name':'LI_AT', 'value':'AQEDASQWXX0BZxscAAABZldw6QwAAAFme31tDE4At-yQCIzof164hQ_orjwoB5TT3sOrRw0CcmYpVdtGlOVorQEcxR6wWgtOwOiba_P2JT7xY12d_mYCW4ZtY1w4q7X8yl_AtQJwtnWKUN8b3gzQXg_F'})
except:
continue
try:
name = driver.find_element_by_xpath("//*[@class='pv-top-card-section__name inline Sans-26px-black-85%']")
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__company-name text-align-left ml2 Sans-15px-black-85%-semibold lt-line-clamp lt-line-clamp--multi-line ember-view']")
emp=emp.text
except:
emp= "na"
try:
rol = driver.find_element_by_xpath("//*[@class='lt-line-clamp__line lt-line-clamp__line--last']")
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, '--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']
df_1 = pd.DataFrame(columns=columns)
lsst=[]
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=""
j = data['experiences']['jobs']
for i in j:
print(i["title"])
print(i["company"])
print(i["date_range"])
print(i["location"])
print(i["description"])
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=""
lst = [name,headline,company, school,location,summary,skills,publications,certifications,courses,projects,honors,languages,organizations,interests]
lsst.append(lst)
lst = []
df_1=pd.DataFrame(lsst,columns=['name','headline','company', 'school','location','summary','skills','publications','certifications','courses','projects','honors','languages','organizations','interests'])
# DF TO EXCEL
writer = ExcelWriter('PythonExport.xlsx')
df_1.to_excel(writer,'Sheet5')
writer.save()
# DF TO CSV
df_1.to_csv('PythonExport.csv', sep=',')