Every week I have to gather a bunch of links and put them in a .txt file so I want to make a script that will go to each website and scrape the links for me. One of these websites is Spotify, I need to grab the share link of the latest episode of a podcast that is on Spotify. Does anyone know how I could do that ?
I already tried writing a script that ended up not working, I inspected the Spotify website source code and found the hyperlink to the share button, it is the one from the latest episode but in a week it won't be. So how can I make sure that every week it will grab the newest one ?
Here's the script:
import requests
from bs4 import BeautifulSoup
links_list = []
url = 'https://open.spotify.com/episode/5KFfAfI3udBlTYxmZF4YUe?si=74aee969910d4577&nd=1'
response = requests.get(url)
if response.ok:
soup = BeautifulSoup(response.text, 'lxml')
links = soup.findAll('link')
for link in links:
a = links.find('href')
result = a['href']
links_list.append(link)
print(len(links_list))
And here's the error I'm getting:
Traceback (most recent call last):
File "test_url.py", line 18, in <module>
a = links.find('href')
File "/Users/theo.wizman/Library/Python/3.8/lib/python/site-packages/bs4/element.py", line 2253, in __getattr__
raise AttributeError(
AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?