如何使用 Python 从 URL 解析文件扩展名
如果你有如下 URL
example.txt
https://logodix.com/logo/1667872.jpg?param=value而你只想找到文件扩展名(本例中为 .jpg),使用以下代码:
parse_extension.py
from urllib.parse import urlsplit
import os.path
url = "https://logodix.com/logo/1667872.jpg?param=value"
path = urlsplit(url).path
extension = os.path.splitext(path)[-1] # 例如 ".jpg"Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow