如何创建检查网站可用性的python函数?
我目前编写的代码如下:如何创建检查网站可用性的python函数?,python,function,Python,Function,我目前编写的代码如下: def Ws_availbality(url): check = print(urllib.request.urlopen("https://www.youtube.com/").getcode()) if check == 200: print ("Website is running") else: print("The website is currently down") Ws_availbality('h
def Ws_availbality(url):
check = print(urllib.request.urlopen("https://www.youtube.com/").getcode())
if check == 200:
print ("Website is running")
else:
print("The website is currently down")
Ws_availbality('https://www.youtube.com/')
问题是,尽管它返回200,但我无法执行if语句。它只执行else语句。我也对不同的功能方法持开放态度 您必须将打印内容移到其他位置:
def Ws_availbality(url):
check = urllib.request.urlopen("https://www.youtube.com/").getcode()
print(check)
if check == 200:
print ("Website is running")
else:
print("The website is currently down")
Ws_availbality('https://www.youtube.com/')
print返回None,所以check是None。print做什么?