except Exception: traceback.print_exc() try: driver.delete_all_cookies() driver.quit() except Exception: print("exception inside exception!") sleep(5) continue # This will cause a browser window to open try: print("before implicitly wait") driver.implicitly_wait(15) driver.maximize_window() sleep(5) if len(driver.window_handles) > 1: driver.switch_to.window(driver.window_handles[0]) except Exception: traceback.print_exc() driver.delete_all_cookies() driver.quit() sleep(5) continue # The login user name , password will be derived from data dump in the names table # Once an enrolment is completed, a record will be inserted into the creds table with the credentials. # creds is the master creds table, the individiual courses will also have its own creds table with user name and password. # So redundant creds data, but this way its easier if (runMode == 'ENROLMENT'):
def loggin(ema, pas): try: browser = TorBrowserDriver(tbb_dir, tor_cfg=cm.USE_STEM) except: # selenium.common.exceptions.WebDriverException: Message: Access is denied. (os error 5) # mozilla is updating print('probably updating sleep 30') sleep(30) browser = TorBrowserDriver(tbb_dir, tor_cfg=cm.USE_STEM) # connect to site try: browser.load_url( "https://www.udemy.com/join/login-popup/?locale=en_US&response_type=html&next=https%3A%2F%2Fwww.udemy.com%2F", wait_on_page=5, wait_for_page_body=True) except: # selenium.common.exceptions.NoSuchWindowException: Message: Browsing context has been discarded try: browser = TorBrowserDriver(tbb_dir, tor_cfg=cm.USE_STEM) except: # selenium.common.exceptions.WebDriverException: Message: Access is denied. (os error 5) # mozilla is updating print('probably updating sleep 30') sleep(30) browser = TorBrowserDriver(tbb_dir, tor_cfg=cm.USE_STEM) browser.load_url( "https://www.udemy.com/join/login-popup/?locale=en_US&response_type=html&next=https%3A%2F%2Fwww.udemy.com%2F", wait_on_page=5, wait_for_page_body=True) # reg_el.click() # maximise browser.maximize_window() # Scroll browser.execute_script("window.scrollTo(0,100)") try: email_el = browser.find_element_by_id("email--1") except: sleep(10) try: email_el = browser.find_element_by_id("email--1") except: return False email_el.send_keys(ema) # enter password pass_el = browser.find_element_by_id("id_password") pass_el.send_keys(pas) # find submit link sub_el = browser.find_element_by_id('submit-id-submit') # click submit sub_el.click() sleep(2) # check try: avatar = browser.find_element_by_id('u711-popover-trigger--18') except: avatar = None if avatar: return browser elif 'udemy.com' in browser.current_url: return browser else: return None