前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >零代码编程:用ChatGPT批量下载Invest Like the Best的投资主题播客音频

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

作者头像
AIGC部落
发布2024-06-24 15:35:13
920
发布2024-06-24 15:35:13
举报
文章被收录于专栏:Dance with GenAIDance with GenAI

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

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

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

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

然后找到播客文件标题:

<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 &amp; 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生成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}!')

运行,下载成功:

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-11-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Dance with GenAI 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档