如何在Python 3中的pytube模块中更改用户代理

时间:2019-06-30 15:26:36

标签: python-3.x user-agent pytube

我正在尝试使用pytube模块下载youtube视频,但是每次运行它都会出现此错误:

raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

这是我要制作的网络应用程序

代码:

from pytube import Youtube

print("What would you like to download ?")
print(f"1/Youtube Video, 2/Image, 3/Song")
userinput = int(input())

if userinput == 1:
    n()


def n():
    print("insert url:")
    u = input()
    download_videos(u)


def download_videos(link):
    yt = YouTube(link)
    yt.streams.filter(progressive=True, file_extension='mp4').order_by(
        'resolution').desc().first().download()

0 个答案:

没有答案