Here is an example code using BeautifulSoup to extract the track listing table from a Wikipedia page and loop through each row:
main.py652 chars18 lines
This code retrieves the track listing table from a Wikipedia page (in this case, the album "The Dark Side of the Moon"), uses BeautifulSoup to extract all rows, and then loops through each row to extract the track number, name, and length from the corresponding td
tags. The if cols:
statement skips the header row of the table, which does not contain any td
tags. The resulting information is printed for each track using an f-string.
gistlibby LogSnag