parsing an html view of an xml file with beautifulsoup?

Viewed 41

I'm trying to scrape some simple data from an XML file that is only accessible as an HTML page.

import requests
import pprint
import pandas as pd
from bs4 import BeautifulSoup

url = "https://musicbrainz.org/ws/2/artist/?query=artist:massive-attack"
resp = requests.get(url).text
soup = BeautifulSoup(resp, 'html.parser')
something = soup.find_all(string="artist")
metadata = soup.select("#folder0 > div:nth-child(1)")
beginarea = soup.select("#folder3 > div.opened > div:nth-child(1) > span:nth-child(2)")
print(something) 

Whenever I try to select an element and print its contents, I get []. I've tried selector and the BeautifulSoup search methods, as well as parsing it as an XML file with ElementTree. What am I missing here? I can't seem to get any data from the page at all. Thank you.

1 Answers
from bs4 import BeautifulSoup
import requests


def main(url):
    r = requests.get(url)
    soup = BeautifulSoup(r.text, 'lxml')
    goal = [x.text for x in soup.select('area + name')]
    print(goal)


main('https://musicbrainz.org/ws/2/artist/?query=artist:massive-attack')

Output:

['Bristol', 'United Kingdom', 'United States', 'Australia', 'Sweden', 'New Jersey', 'Japan', 'France', 'United Kingdom', 'Australia', 'United Kingdom', 'Germany', 'United States', 'Germany', 'United Kingdom', 'France', 'Quebec']
Related