首页 > 解决方案 > 在没有正则表达式的情况下在 python 中验证 https URL

问题描述

我正在尝试从我的输入中验证一个 URL,该 URL 需要验证它是否为 https。我看到许多使用正则表达式、urlparser、urllib 的解决方案

我在 python 中尝试了不同的模块,比如验证器集合

validators.url.url(value, public=False)
url('http://foobar.dk') - returns True or False
is_url('https://foobar.dk') - returns True or False

但这告诉我对于 http 和 https,我想为除“https”之外的任何 URL 抛出错误。是否有任何模块可以在 python 中仅验证 https URL?

标签: pythonpython-3.xvalidationurl

解决方案


可以加第二张支票吗?

if not my_url.startswith("https"):
    raise ValueError(f"URL {my_url} does not starts with https")

推荐阅读