Метод 1: использование API веб-сайта Chord (например, Ultimate Guitar)
import requests
def get_chords(song_title, artist):
url = f"https://api.ultimateguitar.com/api/search?type=Chords&query={song_title} {artist}"
response = requests.get(url)
data = response.json()
if data["data"]:
chords = data["data"][0]["attributes"]["chords"]
return chords
return None
song_title = "idgaf"
artist = "BoyWithUke"
chords = get_chords(song_title, artist)
if chords:
for chord in chords:
print(chord)
else:
print("Chords not found.")
Метод 2. Получение веб-страниц с веб-сайта Chord (например, Ultimate Guitar)
import requests
from bs4 import BeautifulSoup
def get_chords(song_title, artist):
url = f"https://www.ultimate-guitar.com/search.php?search_type=title&value={song_title} {artist}"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
chord_div = soup.find("div", class_="js-store")
if chord_div:
chords = chord_div["data-store"]
# Extract and process the chords from the data
# ...
return chords
return None
song_title = "idgaf"
artist = "BoyWithUke"
chords = get_chords(song_title, artist)
if chords:
for chord in chords:
print(chord)
else:
print("Chords not found.")
Обратите внимание, что приведенные примеры методов предполагают наличие информации об аккордах на определенном веб-сайте (например, Ultimate Guitar). Доступность и законность информации об аккордах могут различаться в зависимости от песни и статуса ее авторских прав. Всегда лучше уважать права интеллектуальной собственности художников и использовать официальные источники, если они доступны.