-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrapper.py
192 lines (99 loc) · 2.98 KB
/
scrapper.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
#!/usr/bin/env python
# coding: utf-8
# In[7]:
get_ipython().system('pip install selenium')
get_ipython().system('pip install beautifulsoup4')
# In[60]:
import os,random,sys,time
from urllib.parse import urlparse
from selenium import webdriver
from bs4 import BeautifulSoup
# In[61]:
browser = webdriver.Chrome('driver/chromedriver.exe')
# In[62]:
browser.get('https://www.linkedin.com/uas/login')
# In[63]:
file = open('config.txt')
lines = file.readlines()
username = lines[0]
password = lines[1]
# In[64]:
elementID = browser.find_element_by_id('username')
elementID.send_keys(username)
# In[65]:
elementID = browser.find_element_by_id('password')
elementID.send_keys(password)
# In[66]:
elementID.submit()
# In[40]:
def replaceSpaces(string):
# Remove remove leading and trailing spaces
string = string.strip()
i = len(string)
# count spaces and find current length
space_count = string.count(' ')
# Find new length.
new_length = i + space_count * 2
# New length must be smaller than length
# of string provided.
if new_length > 1000:
return -1
# Start filling character from end
index = new_length - 1
string = list(string)
# Fill string array
for f in range(i - 2, new_length - 2):
string.append('0')
# Fill rest of the string from end
for j in range(i - 1, 0, -1):
# inserts %20 in place of space
if string[j] == ' ':
string[index] = '0'
string[index - 1] = '2'
string[index - 2] = '%'
index = index - 3
else:
string[index] = string[j]
index -= 1
return ''.join(string)
# In[84]:
comp_name = replaceSpaces("Axis Bank Ltd.")
print(comp_name)
# In[85]:
browser.get('https://www.linkedin.com/search/results/companies/?keywords='+comp_name)
# In[86]:
soup = BeautifulSoup(browser.page_source)
# In[87]:
def getCompanyLink(soup):
pav = soup.find('ul',{'class':'search-results__list list-style-none'})
links = pav.findAll('a',{'class':'search-result__result-link ember-view'})
company_link = 'https://www.linkedin.com'+links[0].get('href')
return company_link
# In[163]:
def getprofiles(soup):
pav = soup.find('ul',{'class':'org-people-profiles-module__profile-list'})
links = pav.findAll('a',{'class':'link-without-visited-state ember-view'})
list_CEO = []
i= 1
for link in links:
user_link = link.get('href')
i += 1
list_CEO.append(user_link)
if(i>=5):
break
return list_CEO
# In[89]:
company_link = getCompanyLink(soup)
# In[146]:
#For CEO Search
browser.get(company_link+'/people/?keywords=CEO')
# In[164]:
#For CEO url list
comp_prof = []
soup = BeautifulSoup(browser.page_source)
comp_prof = getprofiles(soup)
print(comp_prof)
# In[58]:
#For Marketing Manager
browser.get(company_link+'/people/?keywords=manager')
# In[ ]: