如何围绕HTTP错误403:使用下载链接下载视频时禁止错误

发布于 2025-01-28 20:15:02 字数 612 浏览 1 评论 0原文

我正在处理一个代码,在该代码中,我使用Selenium访问网站,并在下载字段中放置链接,然后从下载按钮中提取下载链接,然后使用urlllib.request下载视频。 我设法做到了,直到提取下载链接,但是当我尝试下载时,我会遇到403错误。这是我的代码:

req = Request(downloadlink, headers={
          'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36'})
urlretrieve(downloadlink, r'C:\some\place\on\my\pc\file_name')

我尝试将包含标题的请求既发送到主网站又是视频下载链接,但是每次我遇到此403错误时。有什么办法解决这个问题吗?

PS:

  1. 该网站是一个下载器网站,您将视频URL从例如Tiktok或Reddit中放置,它向您显示了一些底线的底层。
  2. 此下载链接可直接下载系统上的媒体,这意味着如果您在Windows上单击它,则询问您要在哪里保存它的窗口会弹出。

I'm working on a code in which I access a website using selenium and put a link in a download field then extract the download link from download button and download the video using urllib.request.
I managed to do it until extracting the download link but when I try to download it I get this 403 error. here is my code:

req = Request(downloadlink, headers={
          'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36'})
urlretrieve(downloadlink, r'C:\some\place\on\my\pc\file_name')

I tried sending the request containing the headers both to the main website and the video download link but every time I'm getting this 403 error. is there any way to get around this?

P.S:

  1. the website is a downloader website which you put video url from for example tiktok or reddit and it shows you some bottoms to downland it.
  2. this download link directly downloads the media on system, meaning if you click on it on windows the window which asks you where you want to save it pops up.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文