已解决
使用RoboBrowser和Python下载音频
来自网友在路上 169869提问 提问时间:2023-10-19 14:54:45阅读次数: 69
最佳答案 问答题库698位专家为你答疑解惑
以下是一个使用RoboBrowser和Python下载音频的下载器程序,同时使用了https://www.duoip.cn/get_proxy获取代理服务器:
import os
import time
from robobrowser import RoboBrowser
from urllib.request import urlopendef get_audio_url(keyword, proxy=None):browser = RoboBrowser(history=True, proxy=proxy)browser.open("https://www.baidu.com/s?wd=" + keyword)time.sleep(3)audio_url = browser.select("audio[src]")[0].attrs["src"]return audio_urldef download_audio(audio_url, output_file, proxy=None):proxy_support = {"http": proxy, "https": proxy} if proxy else {}with urlopen(audio_url, context=proxy_support) as response:with open(output_file, "wb") as outfile:outfile.write(response.read())def get_proxy():proxy_url = "https://www.duoip.cn/get_proxy"with urlopen(proxy_url) as response:return response.read().decode("utf-8")if __name__ == "__main__":keyword = "你的关键词"output_file = "音频保存路径"proxy = get_proxy()audio_url = get_audio_url(keyword, proxy)download_audio(audio_url, output_file, proxy)
在这个程序中,我们首先获取代理服务器地址,然后使用RoboBrowser打开www.baidu.com,搜索关键词,获取音频URL,最后使用urllib.request下载音频文件。请注意,这个程序需要在Python环境中运行,并且需要安装RoboBrowser库。
查看全文
99%的人还看了
相似问题
猜你感兴趣
版权申明
本文"使用RoboBrowser和Python下载音频":http://eshow365.cn/6-19715-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!
- 上一篇: DHorse v1.4.2 发布,基于 k8s 的发布平台
- 下一篇: 企业如何搭建自己的知识库?