def scan(self, max_scan_count): try: wait = fmk.Wait_Until(self.driver) # Wait until main page has been loaded wait.wait_xpath('//ul[@class="tabbed-primary-navigation"]') self.scroll_page() self.driver.execute_script("window.scrollTo(0, 0);") elements = self.driver.find_elements_by_class_name('slider-item') self.shows = [] counter = 0 if len(elements) < max_scan_count: max_scan_count = len(elements) while counter < max_scan_count: try: element = elements[counter] # SELECT ELEMENT show_container = element.find_element_by_css_selector("p.fallback-text") url_container = element.find_element_by_css_selector("a[role='link']") # GET INFORMATION show_name = show_container.get_attribute('innerHTML') url = url_container.get_attribute('href') # SAVE SHOW show = Show(show_name, url, element) self.shows.append(show) except exceptions.NoSuchElementException: pass counter += 1 except: pass
def deep_scan(self, show): is_series = False try: container = self.get_show_container(show) seasons_length = self.get_seasons_length(container) wait = fmk.Wait_Until(self.driver) for i in range(seasons_length): season_number = self.get_next_season(i) season = Season(season_number) episode_load_wait = WebDriverWait(self.driver, 10) element = episode_load_wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'div.episodeWrapper div.episodeLockup div.episodeTitle'))) container = self.driver.find_element_by_css_selector('div.episodesContainer') # print(container.get_attribute("innerHTML")) # Select episodes in container season_episodes = container.find_elements_by_css_selector('div.slider-item') for season_episode in season_episodes: episode = self.get_episode(season_episode) season.episodes.append(episode) show.seasons.append(season) is_series = True except exceptions.NoSuchElementException: pass return is_series
def scan(self, max_scan_count): try: wait = fmk.Wait_Until(self.driver) # Wait until main page has been loaded wait.wait_xpath('//div[@class="pv-nav-primary-components"]') self.scroll_page() self.driver.execute_script("window.scrollTo(0, 0);") elements = self.driver.find_elements_by_css_selector('div.tst-packshot-link') print(len(elements)) self.shows = [] counter = 0 if len(elements) < max_scan_count: max_scan_count = len(elements) while counter < max_scan_count: try: element = elements[counter] # SELECT ELEMENT info_container = element.find_element_by_css_selector('a') # GET INFORMATION show_name = info_container.get_attribute('aria-label') url = info_container.get_attribute('href') # SAVE SHOW show = Show(show_name, url, element) self.shows.append(show) except exceptions.NoSuchElementException: pass counter += 1 except: pass
def get_seasons_length(self, container): wait = fmk.Wait_Until(self.driver) # Iterate through seasons wait.wait_css('div.nfDropDown') dropbox = container.find_element_by_css_selector("div.nfDropDown") dropbox.click() wait.wait_css("a.sub-menu-link") seasons_buttons = self.driver.find_elements_by_css_selector("a.sub-menu-link") return len(seasons_buttons)
def get_show_container(self, show): wait = fmk.Wait_Until(self.driver) expand_show = show.container.find_element_by_css_selector('div.bob-jawbone-chevron') expand_show.click() wait.wait_xpath("//li[@id='tab-Overview']") container = self.driver.find_element_by_xpath('//div[@class="jawBoneFadeInPlaceContainer"]') episodes_selector = container.find_element_by_css_selector('li#tab-Episodes') episodes_selector.click() return container
def get_show_info(self): try: blank = '<yt-formatted-string force-default-style="" class="style-scope ytd-video-primary-info-renderer"></yt-formatted-string>' wait = fmk.Wait_Until(self.driver).wait_different_css( 'h1.title', blank) title_container = self.driver.find_element_by_css_selector( 'h1.title') title_div = title_container.find_element_by_css_selector( 'yt-formatted-string') self.show_name = title_div.get_attribute('innerHTML') except exceptions.NoSuchElementException: print("Failed to get title")
def get_next_season(self, season_n): wait = fmk.Wait_Until(self.driver) if season_n > 0: # Click on the dropdown dropdown = self.driver.find_element_by_css_selector("div.nfDropDown") dropdown.click() # Click on season and get seasons name wait.wait_css("a.sub-menu-link") select_season = self.driver.find_elements_by_css_selector("a.sub-menu-link") season_name = select_season[season_n].get_attribute('innerHTML') select_season[season_n].click() season_info = season_name.split(' ') season_number = int(season_info[1]) return season_number
def get_episode(self, season_episode): wait = fmk.Wait_Until(self.driver) # Get name wait.wait_css("div.episodeTitle p", container=season_episode) episode_name_container = season_episode.find_element_by_css_selector('div.episodeTitle p') episode_name = episode_name_container.get_attribute('innerHTML') # Get link wait.wait_xpath('//a[@data-uia="play-button"]', container=season_episode) episode_url_container = season_episode.find_element_by_css_selector('a[data-uia="play-button"]') episode_url = episode_url_container.get_attribute('href') # Get number wait.wait_css("div.episodeNumber span", container=season_episode) episode_number_container = season_episode.find_element_by_css_selector("div.episodeNumber span") episode_number = int(episode_number_container.get_attribute('innerHTML')) episode = Episode(episode_name, episode_url, episode_number) return episode
def scan(self, max_scan_count): try: wait = fmk.Wait_Until(self.driver) # Wait until main page has been loaded wait.wait_xpath('//div[@id="content"]') self.scroll_page() self.driver.execute_script("window.scrollTo(0, 0);") elements = self.driver.find_elements_by_css_selector( 'a#video-title') if len(elements) == 0: elements = self.driver.find_elements_by_css_selector( 'a#video-title-link') self.shows = [] counter = 0 if len(elements) < max_scan_count: max_scan_count = len(elements) while counter < max_scan_count: try: element = elements[counter] # GET INFORMATION show_name = element.get_attribute('title') url = element.get_attribute('href') # SAVE SHOW show = Show(show_name, url, element) self.shows.append(show) except exceptions.NoSuchElementException: pass counter += 1 except: pass