select a music artist and one of their albums for which wikipedia has a web page with a track list. create a variable url that takes the string url of the wikipedia article. in python

To select a music artist and one of their albums for which Wikipedia has a web page with a track list using requests and beautifulsoup libraries in Python, you can follow these steps:

  1. Choose a music artist and their album, for which Wikipedia has a web page with a track list. Let's use the example of the album "Thriller" by Michael Jackson.

  2. Use the requests library to send a GET request to the Wikipedia page for that album, and store the response in a variable:

main.py
import requests

url = "https://en.wikipedia.org/wiki/Thriller_(Michael_Jackson_album)"
response = requests.get(url)
117 chars
5 lines
  1. Use the beautifulsoup library to parse the HTML content of the response, and extract the track list from the page:
main.py
from bs4 import BeautifulSoup

soup = BeautifulSoup(response.content, 'html.parser')
tracklist_table = soup.find('table', {'class': 'tracklist'})
tracks = tracklist_table.find_all('td', {'class': 'tracklist_track'})
216 chars
6 lines
  1. Print the track list:
main.py
for track in tracks:
    print(track.text.strip())
51 chars
3 lines

This will output the track list of the album "Thriller" by Michael Jackson, which is extracted from the Wikipedia page using Python.

gistlibby LogSnag