Created
October 20, 2022 18:07
-
-
Save aleenprd/04589e2d358fd83c06980e41d909a273 to your computer and use it in GitHub Desktop.
Get Links to Episodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re as regex | |
def get_episodes_links(link: str, driver_service) -> List[str]: | |
"""Retrieve links to episodes, from series' season main page. | |
Args: | |
link (str): link to season main page. | |
driver_service (Service): a Chrome web driver. | |
Returns: | |
links (List[str]): a list of links to the episodes. | |
""" | |
soup = make_soup_with_selenium(link, driver_service) | |
website = "https://www.imdb.com" | |
links = [] | |
for link in soup.find_all('a', href=True): | |
href = link["href"] | |
# Episode links end with the following Regex | |
if bool(regex.search('=ttep_ep\d$', href)): | |
links.append(href) | |
links = list(set(links)) | |
links.sort() | |
links = [f"{website}{l}" for l in links] | |
return links |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment