"""Spotify parsing module.""" import requests from bs4 import BeautifulSoup class ParsingError(Exception): """Error parsing the Spotify page.""" pass def get_artist_name(spotify_url: str) -> str: """Get artist name by artist/ url from title block.""" response = requests.get(spotify_url) response.raise_for_status() soup = BeautifulSoup(response.text, features='html.parser') try: title_block = soup.find('title') print(title_block) # exp: Bone Nest | Spotify artist_name = title_block.text.split('|')[0].strip() if artist_name: return artist_name else: raise ParsingError('Block was parsed, but the data is empty.') except Exception as error: raise ParsingError('Parsing artist name is failed.', str(error))