如何与Python在Spotify中刮擦共享链接?
每周我都必须收集一堆链接并将它们放入 .txt 文件中,因此我想制作一个脚本来访问每个网站并为我抓取链接。其中一个网站是 Spotify,我需要获取 Spotify 上最新一集播客的共享链接。有谁知道我该怎么做?
我已经尝试编写一个脚本,但最终无法正常工作,我检查了 Spotify 网站源代码,找到了共享按钮的超链接,这是最新一集的链接,但一周后就不会了。那么我怎样才能确保每周它都会获取最新的呢?
这是脚本:
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))
这是我收到的错误:
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()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如@sergeyk所提到的,Spotify拥有公共API,可以获取播客列表:
在Python中,您可以使用 Spotipy 以便于与API集成:
此片段应检索“在分类帐”播客的最新50集。
AS @SergeyK mentioned, Spotify has public APIs to get a list of podcast episodes: https://developer.spotify.com/console/get-show-episodes/
In Python, you can use Spotipy for easy integration with the APIs:
This snippet should retrieve the latest 50 episodes for the "On The Ledger" podcast.