国内使用pytube下载youtube视频

使用示例:
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=PMivT7MJ41M')
yt.streams.first().download(save_dir, 'mv')
遇到的问题:
1.由于目标计算机积极拒绝,无法连接
在浏览器能够访问youtube的情况下,出现此问题是因为没有设置代理,进行如下设置
proxy_handler = {
"http": " http://127.0.0.1:41091", # 端口在代理设置中查看
'https': ' http://127.0.0.1:41091'
}
url = 'https://www.youtube.com/watch?v=PMivT7MJ41M'
yt = YouTube(url,proxies=proxy_handler)

注意:这里一定要使用httphttps代理,如果是SOCKS5则会报错误:urlopen error Remote end closed connection without response

参考链接:
 
2.AttributeError: 'NoneType' object has no attribute 'span'
按照如下方式重新安装pytube
pip uninstall pytube
pip install git+https://github.com/rmerzouki/pytube
参考链接:
 
posted @ 2022-03-17 14:56  发言稿  阅读(1580)  评论(0编辑  收藏  举报