It looks like if a request
adds a user-agent
, Spotify will preform additional checks. This may be fixed by adding all the headers. Alternatively you can set the user agent to a Brower that Spotify doesn't know about e.g TEST.
I've got the following scrape code to work without any headers, so I wouldn't admit headers unless there was a specific reason. (I've only added it, because of the question in the title).
import requests
from bs4 import BeautifulSoup
urls = [
'https://open.spotify.com/artist/711MCceyCBcFnzjGY4Q7Un',
'https://open.spotify.com/artist/4npEfmQ6YuiwW1GpUmaq3F'
]
headers = {
'user-agent': 'TEST'
}
for url in urls:
response = requests.get(url, headers=headers)
html = response.text
soup = BeautifulSoup(html, 'html.parser')
#print(soup.prettify())
print(soup.find('h1').text.strip())
Output:
AC/DC
Ava Max