python请求冻结程序



我试图使用请求从网页获取状态代码,但没有输出,程序在请求时停止。get

我的代码

if requests.get("https://storage.googleapis.com/linear-theater-254209.appspot.com/v5.4animu.me/Hunter-x-Hunter/Hunter-x-Hunter-Episode-1-1080p.mp4").status_code == 200:
print("link is working")
else:
print("link is not working")

代码在另一台机器上工作

我想它正在下载视频,但我只想要状态码

我以前没有使用请求下载文件,所以IDK关于

编辑:它也适用于Collabororyhttps://colab.research.google.com/drive/1yECaNKQNsyDUuGhBfcEa2OhDUUqqeg_q

您可以使用requests.head()来获得如下标题:

import requests
if requests.head("https://storage.googleapis.com/linear-theater-254209.appspot.com/v5.4animu.me/Hunter-x-Hunter/Hunter-x-Hunter-Episode-1-1080p.mp4").status_code == 200:
print("link is working")
else:
print("link is not working")

requests.get()将下载请求的URL,由于您在此处请求的文件不小,可能需要一些时间。如果您想检查标题和状态代码,最好使用requests.head()

最新更新