Python中的Nonetype类型 None

如果一个NoneType类型的变量需要过滤  可以 用  “is  None”去判断   

如果是NoneType  他会返回True

if __name__ == '__main__':
    url="http://www.katoombagroup.org/details.php?id=56"


    r = requests.get(url)
    print(type(r))  #
    demo = r.text
    print(type(demo))   #
    soup = BeautifulSoup(demo, 'html.parser')
    links=soup.find_all('a')
    print(type(links))
    for link in links:
        new_url = link.get('href')
        print(type(new_url))
        if new_url is None:
            print(True)
        print("new_url:",new_url)

 

 





True
new_url: None

new_url: ../

new_url: ../

new_url: http://www.katoombagroup.org/about.php?focus=roles

new_url: http://www.katoombagroup.org/about.php?focus=mission

你可能感兴趣的:(python)