Created
June 4, 2023 17:56
-
-
Save Shawn-Armstrong/80dd5557a4655f365285fcbb501ff2de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from googleapiclient.discovery import build | |
from google.oauth2 import service_account | |
from selenium import webdriver | |
import time | |
SERVICE_ACCOUNT_FILE = 'keys.json' | |
SCOPES = ['https://www.googleapis.com/auth/spreadsheets'] | |
creds = None | |
creds = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES) | |
SAMPLE_SPREADSHEET_ID = '<REDACTED>' | |
service = build('sheets', 'v4', credentials=creds) | |
sheet = service.spreadsheets() | |
result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID, range="Sheet1!A1:B188").execute() | |
values = result.get('values', []) | |
f = open("CSE LinkedIn.txt","w+") | |
number_of_entries = len(values); | |
# Open Google Chrome driver | |
driver_path = "/Users/shawn/OneDrive/Desktop/chromedriver_win32/chromedriver.exe" | |
driver = webdriver.Chrome(driver_path) | |
driver.get('https://www.linkedin.com') | |
# login to LinkedIn | |
username = driver.find_element_by_id('session_key') | |
username.send_keys('<REDACTED>') | |
password = driver.find_element_by_id('session_password') | |
password.send_keys('<REDACTED>') | |
log_in_button = driver.find_element_by_class_name('sign-in-form__submit-button') | |
log_in_button.click() | |
for i in range(120, 186): | |
time.sleep(10) | |
profile_url = str(values[i][1]); | |
driver.get(profile_url) | |
profile_picture = driver.find_element_by_class_name('pv-top-card-profile-picture__image') | |
profile_image_src = profile_picture.get_attribute("src") | |
message = "" + profile_image_src | |
# No profile image, display default. | |
if message[0] != 'h': | |
message = "https://postimg.cc/56Z2B61w" | |
aoa = [[message]] | |
rangeValue = "Sheet1!C" + str(i+1) | |
request = sheet.values().update(spreadsheetId=SAMPLE_SPREADSHEET_ID, range=rangeValue, | |
valueInputOption="USER_ENTERED", body={"values": aoa}).execute() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment