Skip to content

Commit

Permalink
Added safe exception handling if Facebook doesn't make the ajax call …
Browse files Browse the repository at this point in the history
…within 2 minutes.
  • Loading branch information
bhamodi committed Jul 12, 2015
1 parent b68a3c5 commit bdd0fd0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from datetime import datetime
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException

def main():
print('\nStarting script...')
Expand Down Expand Up @@ -61,8 +62,11 @@ def main():
}
window.XMLHttpRequest.prototype.open = openReplacement;'''
driver.execute_script(script)
doneScraping = driver.find_element_by_id('doneScraping')
time.sleep(5)
try:
doneScraping = driver.find_element_by_id('doneScraping')
time.sleep(5)
except NoSuchElementException:
pass

# Scrape the number of online friends
onlineFriendsCount = int(driver.find_element_by_xpath('//*[@id="fbDockChatBuddylistNub"]/a/span[2]/span').text.strip('()'))
Expand Down

0 comments on commit bdd0fd0

Please sign in to comment.