-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraping_contact_information_from_linkedin.py
52 lines (40 loc) · 1.79 KB
/
scraping_contact_information_from_linkedin.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
from selenium import webdriver
from bs4 import BeautifulSoup
import requests
from time import sleep
class LinkedIn:
def __init__(self, username='d33ps3curity@gmail.com', password='d33ps3curity'):
self.driver = webdriver.Chrome('C:\\Users\\d33ps3curity\\Downloads\\chromedriver_win32\\chromedriver.exe')
main_url = 'https://www.linkedin.com'
self.username = username
self.password = password
self.search_username = "Pranay Kasavaraju"
self.driver.get(main_url)
sleep(3)
self.login()
self.search_user(self.search_username)
self.driver.close()
def login(self):
log_in_button = self.driver.find_element_by_xpath('//a[@class="nav__button-secondary"]')
log_in_button.click()
sleep(3)
username_input = self.driver.find_element_by_xpath('//input[@id="username"]')
username_input.send_keys(self.username)
password_input = self.driver.find_element_by_xpath('//input[@id="password"]')
password_input.send_keys(self.password)
submit_button = self.driver.find_element_by_xpath('//button[@class="btn__primary--large from__button--floating"]')
submit_button.submit()
sleep(2)
def search_user(self, search_username):
sleep(2)
search_bar = self.driver.find_element_by_xpath('//input[@placeholder="Search"]')
search_bar.send_keys(search_username)
search_bar.submit()
sleep(2)
get_contact_info = self.driver.find_element_by_xpath('//a[@id="ember49"]')
get_contact_info.click()
soup = BeautifulSoup(self.driver.page_source, 'lxml')
email_soup = soup.find('div', class_='pv-contact-info__ci-container t-14')
print(email_soup.a['href'])
if __name__ == '__main__':
linkedin_app = LinkedIn()