I’m working with a Google Sheets document that contains Gmail addresses. When you hover your mouse over these email addresses, a popup appears showing contact details and the person’s Gmail profile picture. I need to find an efficient method to automatically download these profile images for a large list of email addresses.
Currently, I’m using a Selenium automation script that mimics human behavior by opening the spreadsheet and hovering over each email to capture the images. But this approach is very slow and often fails.
for iteration in range(total_rows):
mouse_actions = ActionChains(browser)
mouse_actions.move_by_offset(0, 25).perform()
time.sleep(4)
picture_elements = browser.find_elements(By.XPATH, '//div[@class="profile-card"]//img')
if picture_elements:
profile_pic_url = picture_elements[0].get_attribute('src')
download_path = f"/home/user/images/profile_{iteration}.png"
urllib.request.urlretrieve(profile_pic_url, download_path)
iteration += 1
Is there a more reliable API or method to retrieve Gmail profile images programmatically?
Been working on similar data extraction for client databases. That Selenium approach won’t work - Google Sheets actively blocks automated scraping with anti-bot measures. Your script breaks because DOM elements change constantly and rate limiting kicks in.
Best solution I’ve found: combine Directory API with batch processing. If you’re working with organizational accounts, Admin SDK Directory API gives direct access to user photos - no popup scraping needed. For external Gmail addresses, use a hybrid approach - People API for known contacts, then fall back to hashed email lookups through Gravatar or Libravatar.
Here’s what others missed: caching strategies. Store successful lookups in a local database so you don’t hit the same APIs repeatedly. Critical when you’re bumping against Google’s rate limits.
definitely check out the Google People API! it lets you get profile pics and you just have to set up OAuth. also, Gmail API might help with avatar stuff too. way better than dealing with selenium! it’s such a hassle.
Hit the same issue a few months ago on a contact management project. Google Contacts API + People API was my best solution. You can fetch contact info and photos using email as the lookup - just need proper OAuth 2.0 setup and batch requests for efficiency. Google stores profile pics on their servers, accessible through API endpoints once you’ve got permissions. Catch is you can only grab photos for contacts who’ve shared publicly or are already in your Google contacts. For emails outside your network, Gravatar works as a fallback since lots of people use it as their universal profile pic.