[summary] Take an url and return list of anime after scraping the site. >>> type(search_scraper("demon_slayer")) Args: anime_name (str): [Name of anime] Raises: e: [Raises exception on failure] Returns: [list]: [List of animes]
(anime_name: str)
| 15 | |
| 16 | |
| 17 | def search_scraper(anime_name: str) -> list: |
| 18 | """[summary] |
| 19 | |
| 20 | Take an url and |
| 21 | return list of anime after scraping the site. |
| 22 | |
| 23 | >>> type(search_scraper("demon_slayer")) |
| 24 | <class 'list'> |
| 25 | |
| 26 | Args: |
| 27 | anime_name (str): [Name of anime] |
| 28 | |
| 29 | Raises: |
| 30 | e: [Raises exception on failure] |
| 31 | |
| 32 | Returns: |
| 33 | [list]: [List of animes] |
| 34 | """ |
| 35 | |
| 36 | # concat the name to form the search url. |
| 37 | search_url = f"{BASE_URL}/search?keyword={anime_name}" |
| 38 | |
| 39 | response = httpx.get( |
| 40 | search_url, headers={"UserAgent": UserAgent().chrome}, timeout=10 |
| 41 | ) # request the url. |
| 42 | |
| 43 | # Is the response ok? |
| 44 | response.raise_for_status() |
| 45 | |
| 46 | # parse with soup. |
| 47 | soup = BeautifulSoup(response.text, "html.parser") |
| 48 | |
| 49 | # get list of anime |
| 50 | anime_ul = soup.find("ul", {"class": "items"}) |
| 51 | if anime_ul is None or isinstance(anime_ul, NavigableString): |
| 52 | msg = f"Could not find and anime with name {anime_name}" |
| 53 | raise ValueError(msg) |
| 54 | anime_li = anime_ul.children |
| 55 | |
| 56 | # for each anime, insert to list. the name and url. |
| 57 | anime_list = [] |
| 58 | for anime in anime_li: |
| 59 | if isinstance(anime, Tag): |
| 60 | anime_url = anime.find("a") |
| 61 | if anime_url is None or isinstance(anime_url, NavigableString): |
| 62 | continue |
| 63 | anime_title = anime.find("a") |
| 64 | if anime_title is None or isinstance(anime_title, NavigableString): |
| 65 | continue |
| 66 | |
| 67 | anime_list.append({"title": anime_title["title"], "url": anime_url["href"]}) |
| 68 | |
| 69 | return anime_list |
| 70 | |
| 71 | |
| 72 | def search_anime_episode_list(episode_endpoint: str) -> list: |
no test coverage detected