天天看点

零代码编程:用ChatGPT批量下载Invest Like the Best的投资播客音频

作者:AIGC部落

Patrick O’Shaughnessy 主持了一档全世界最著名的投资类播客,播客名字叫 Invest Like the Best。 内容是关于投资观念、理财方法、人生规划等。每期嘉宾会分享其擅长的投资策略和产品,还会推荐书籍。

零代码编程:用ChatGPT批量下载Invest Like the Best的投资播客音频

其官网上可以下载全部播客音频:https://investlikethebest.libsyn.com

怎么利用ChatGPT来批量下载呢?

首先看这些播客音频文件,都在class="libsyn-item"的div标签里面;

零代码编程:用ChatGPT批量下载Invest Like the Best的投资播客音频

然后找到播客文件标题:

<div class="libsyn-item-title">

<a href="https://investlikethebest.libsyn.com/scott-davis-rob-wertheimer-lessons-from-the-industrial-titans-invest-like-the-best-ep324">Scott Davis & Rob Wertheimer - Lessons from the Industrial Titans - [Invest Like the Best, EP.324]</a>

播客音频Mp3也很容易找到:

<div class="libsyn-item-content">

<ul class="libsyn-item-free">

<li>

<a href="https://traffic.libsyn.com/secure/investlikethebest/EP.324_-_Lessons_from_Titans_FINAL.mp3">Download this Episode</a></li>

</ul>

</div>

网站一共有17页,每页地址很有规律:

https://investlikethebest.libsyn.com/page/1/size/25 第1页

https://investlikethebest.libsyn.com/page/2/size/25 第2页

https://investlikethebest.libsyn.com/page/17/size/25 17页

现在,可以在ChatGPT中输入提示词了:

你是一个Python编程专家,要完成一个下载网页音频文件的任务,具体步骤如下:

打开网页:https://investlikethebest.libsyn.com/page/{pagenumber}/size/25

其中,参数pagenumber的值是从1到17;

定位class="libsyn-item"的div标签;

在这个div标签内定位class="libsyn-item-title"的div标签,提取第一个a标签的内容,作为音频文件的标题名;

然后定位div class="libsyn-item-content"的div标签,提取其中a标签的href值,作为音频文件下载的URL地址;

下载音频文件,保存到电脑D盘的文件夹:invest-like-the-best

零代码编程:用ChatGPT批量下载Invest Like the Best的投资播客音频

chatgpt生成Python源代码如下:

import os

import requests

from bs4 import BeautifulSoup

# 创建保存音频文件的文件夹

if not os.path.exists('D:/invest-like-the-best'):

os.makedirs('D:/invest-like-the-best')

# 循环访问每一页

for pagenumber in range(1, 18):

url = f'https://investlikethebest.libsyn.com/page/{pagenumber}/size/25'

response = requests.get(url)

# 解析网页内容

soup = BeautifulSoup(response.text, 'html.parser')

# 定位到每一个音频项

for item in soup.find_all('div', class_='libsyn-item'):

# 提取音频标题

title = item.find('div', class_='libsyn-item-title').a.text

# 提取音频下载链接

download_url = item.find('div', class_='libsyn-item-content').a['href']

print(f'Downloading {title}...')

# 下载音频文件

audio_response = requests.get(download_url)

# 保存音频文件

with open(f'D:/invest-like-the-best/{title}.mp3', 'wb') as f:

f.write(audio_response.content)

print(f'Downloaded {title}!')

零代码编程:用ChatGPT批量下载Invest Like the Best的投资播客音频

运行,下载成功:

零代码编程:用ChatGPT批量下载Invest Like the Best的投资播客音频

继续阅读