print("Created a driver successfully!") 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
cursor = connection.cursor() driver = TorBrowserDriver( "/home/ubuntu/Downloads/tor-browser-linux64-8.5.4_en-US/tor-browser_en-US") insightsLogin(driver, "*****@*****.**", "hotmail143") while (True): try: sql = "SELECT `term` FROM `insights` where completed is null order by rand() limit 1" cursor.execute(sql) result = cursor.fetchall() originalTerm = result[0]['term'] print(originalTerm) term = originalTerm.replace("-", " ") driver.implicitly_wait(10) driver.get( "https://www.udemy.com/instructor/marketplace-insights/?q=" + term + "&lang=en") sleep(random.randint(5, 8)) try: demandEl = driver.find_element_by_xpath( '//div[contains(@class,"panel-body")]/div[contains(@class,"course-label-metrics-opportunity")]/div[1]/div/div[2]' ) print(demandEl.text) except NoSuchElementException: print("trying hyphenated...") term = term.replace(" ", "-") driver.get(