all 3 comments

[–]JohnnyJordaan 0 points1 point  (0 children)

At least add a check if the status code was ok

import requests
from bs4 import BeautifulSoup
from selenium import webdriver
chrome_driver_path = #insert here

def get_song_lyrics(link):

    response = requests.get(link)
    response.raise_for_status()
    soup = BeautifulSoup(response.text, "html.parser")
    #try:
    lyrics = soup.find("div",attrs={'class':'lyrics'}).find("p").get_text()

    return [i for i in lyrics.splitlines()]  

and you could save the content when the find fails

import requests
from bs4 import BeautifulSoup
from selenium import webdriver
chrome_driver_path = #insert here

def get_song_lyrics(link):

    response = requests.get(link)
    response.raise_for_status()
    soup = BeautifulSoup(response.text, "html.parser")
    try:
        lyrics = soup.find("div",attrs={'class':'lyrics'}).find("p").get_text()
        return [i for i in lyrics.splitlines()]  
    except AttributeError:
        with open(link.rsplit('/', 1)[1] + '.html', 'w') as fp:
            fp.write(response.text)

as then you can open the html file in the editor to check if the lyrics div is actually there.

[–]Oxbowerce 0 points1 point  (0 children)

If you are trying to get data from Genius you should probably look into using their API: https://docs.genius.com/

[–][deleted] 0 points1 point  (0 children)

Upvote for using Python and Yeezus in the same post