我当前写的代码如下:
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语句。它只是执行其他语句。我也可以接受不同的功能方法。
您必须将打印移动到其他地方:
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/')