10 000 причин, почему нужны гитарные аккорды: научитесь играть песню Мэтта Редмана на гитаре

Вот пример того, как можно получить гитарные аккорды для песни Мэтта Редмана «10,000 Reasons» с помощью кода Python:

import requests
from bs4 import BeautifulSoup
def get_chords(song_name):
    # Prepare the search query
    query = song_name + " guitar chords"
    # Send a GET request to a search engine (e.g., Google)
    response = requests.get("https://www.google.com/search", params={"q": query})
    # Parse the HTML response using BeautifulSoup
    soup = BeautifulSoup(response.text, "html.parser")
    # Find the relevant search results
    search_results = soup.find_all("div", class_="r")
    # Extract the URL of the top search result
    top_result_url = search_results[0].a["href"]
    # Send a GET request to the top search result
    response = requests.get(top_result_url)
    # Parse the HTML response using BeautifulSoup
    soup = BeautifulSoup(response.text, "html.parser")
    # Find the chords in the page
    chords = soup.find_all("pre", class_="c")
    # Extract the text content of the chords
    chord_text = [chord.get_text() for chord in chords]
    return chord_text
# Usage example
song_name = "10,000 Reasons"
chords = get_chords(song_name)
for chord in chords:
    print(chord)

Этот код выполняет поиск в Google по названию песни, за которым следует слово «гитарные аккорды», получает самый популярный результат поиска и извлекает информацию об аккорде со страницы.