Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何创建检查网站可用性的python函数?_Python_Function - Fatal编程技术网

如何创建检查网站可用性的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做什么?