Python检查一个链接是否有效

Python检查一个链接是否有效

from urllib import request

try:
    with request.urlopen(
            "https://www.baidu.com/") as file:
        print(file.status)
        print(file.reason)
except Exception as e:
    print(e)

你可能感兴趣的:(python3)