Fetch_data.py to scrape a song from AZ Lyrics


#1

fetch_data.py

from lxml import html
import requests

source = requests.get("https://www.azlyrics.com/lyrics/gunsnroses/sweetchildomine.html")

tree = html.fromstring(source.content)

lyrics = tree.xpath('/html/body/div[3]/div/div[2]/div[5]/text()')
song_title = tree.xpath('/html/body/div[3]/div/div[2]/b/text()')
artist = tree.xpath('/html/body/div[3]/div/div[2]/div[3]/h2/b/text()')

song = ' '.join(artist).replace("Lyrics", "") + "\n" + ' '.join(song_title) + ' '.join(lyrics)