-
-
Save s1as3r/e3a41dfd6459448f1c84748bf96697e6 to your computer and use it in GitHub Desktop.
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 bs4, requests | |
headers = { | |
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" | |
} | |
def get_link(query: str) -> str: | |
search_url = "https://www.musixmatch.com/search/" + query | |
search_resp = requests.get(search_url, headers=headers) | |
soup = bs4.BeautifulSoup(search_resp.text, "html.parser") | |
links = soup.select("a[href^='/lyrics/']") | |
best_link = "https://www.musixmatch.com" + links[0].get("href") | |
return best_link | |
def get_lyrics(url: str) -> str: | |
resp = requests.get(url, headers=headers) | |
soup = bs4.BeautifulSoup(resp.text, "html.parser") | |
lyrics_paragraphs = soup.select("p.mxm-lyrics__content") | |
lyrics = "\n".join(i.text for i in lyrics_paragraphs) | |
return lyrics |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment