1+ from selenium import webdriver
2+ from selenium .webdriver .common .keys import Keys
3+ from bs4 import BeautifulSoup
4+ from selenium .webdriver .chrome .options import Options
5+ import re
6+ import time
7+ import getpass
8+
9+ chrome_options = Options ()
10+ chrome_options .add_argument ("--window-size=1360,768" )
11+ chrome_options .add_argument ("headless" )
12+ driver = webdriver .Chrome ('./chromedriver' , options = chrome_options )
13+ driver .get ("https://www.linkedin.com" )
14+ unme = driver .find_element_by_id ('session_key' )
15+ passw = driver .find_element_by_id ('session_password' )
16+ print ('Please sign in to your LinkedIn Account:' )
17+ u = input ("Email or phone number: " )
18+ p = getpass .getpass ('Password: ' )
19+ unme .send_keys (u )
20+ passw .send_keys (p )
21+ passw .send_keys (Keys .ENTER )
22+ time .sleep (2 )
23+ if (driver .title == "LinkedIn Login, Sign in | LinkedIn" or driver .title == "LinkedIn: Log In or Sign Up" ):
24+ print ('Invalid Username or Password' )
25+ print ('The program will now exit' )
26+ time .sleep (1 )
27+ exit ()
28+ time .sleep (2 )
29+ print ('Fetching Info (This might take a while)...' )
30+ body = driver .find_element_by_tag_name ('body' )
31+ for i in range (50 ):
32+ body .send_keys (Keys .CONTROL , Keys .END )
33+ time .sleep (5 )
34+ soup = BeautifulSoup (driver .page_source , 'html.parser' )
35+ driver .quit ()
36+ print ('Done' )
37+
38+ divs = soup .find_all ('div' , attrs = {'class' : re .compile ('feed-shared-update-v2 feed-shared-update-v2--minimal-padding full-height relative feed-shared-update-v2--e2e artdeco-card ember-view' )})
39+ ctr = 0
40+ authors = []
41+ sdesc = []
42+ timestamp = []
43+ posts = []
44+ print ('Fetching the latest posts for you...' )
45+ for d in divs :
46+ author = d .find ('div' , attrs = {'class' : re .compile ('feed-shared-actor__meta relative' )})
47+ content = d .find ('div' , attrs = {'class' : re .compile ('feed-shared-update-v2__description-wrapper ember-view' )})
48+ try :
49+ name = author .find ('span' , attrs = {'dir' : 'ltr' })
50+ adesc = author .find ('span' , attrs = {'class' : 'feed-shared-actor__description t-12 t-normal t-black--light' })
51+ added = author .find ('span' , attrs = {'class' : 'visually-hidden' })
52+ post = content .find ('span' , attrs = {'dir' : 'ltr' })
53+ n = name .text
54+ ad = added .text
55+ ads = adesc .text
56+ po = post .text
57+ except AttributeError :
58+ continue
59+ authors .append (n )
60+ sdesc .append (ads )
61+ timestamp .append (ad )
62+ posts .append (po )
63+ if (len (authors )== 0 ):
64+ print ("Oops! Seems the the bot has crashed due to over-usage :(" )
65+ print ("Please try after 10 mins." )
66+ exit ()
67+ print ('Done' )
68+ print ('Choose the post you want to see :' )
69+ for i in range (len (authors )):
70+ print ("\t " + str (i + 1 )+ ". " + authors [i ]+ ". Added: " + timestamp [i ])
71+ ans = "y"
72+ while (ans == "y" ):
73+ ch = int (input ("Enter your choice: " ))
74+ if (ch > len (authors ) or ch < 1 ):
75+ print ("Invalid Choice." )
76+ else :
77+ print (authors [ch - 1 ])
78+ print ("Posted: " + timestamp [ch - 1 ])
79+ print ("Author Description: " + sdesc [ch - 1 ])
80+ print (posts [ch - 1 ])
81+ ans = input ('Want to see other posts? (y/n) ' )
82+ print ('' )
83+ print ("Thank You" )
0 commit comments