如何使用python检查youtube视频是否存在? [英] How to check if a youtube video exists using python?

查看:40
本文介绍了如何使用python检查youtube视频是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这个简单的函数,可以检查一个网站是否存在:

I've got a this simple function, that checks if a website exists:

def try_site(url):
    request = requests.get(url)
    return request.status_code == 200

问题是,对于没有视频的 youtube 网址,仍然存在一个页面——它不会返回 404 或类似的内容.所以我的代码显然认为该页面存在.我将如何检查视频是否存在?

The issue is, that for youtube urls, that don't have videos, there still exists a page -- it doesn't return 404, or anything like that. So my code obviously thinks the page exists. How would I go about checking if a video exists?

推荐答案

获取网页并检查是否有类似视频不可用"之类的文字或页面中的类似内容.

Fetch the web page and check if there is a text like "Video unavailable" or alike in the page.

这篇关于如何使用python检查youtube视频是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆