当我检查type()
BeautifulSoup 元素的 时,它会打印<class 'bs4.element.Tag'>
.
如何检查变量的类型是否为<class 'bs4.element.Tag'>
using if
?
我想这两个以下方法,但它从来没有工作过,即使的类型bs4_element_var
是bs4.element.Tag
。
if type(bs4_element_var) == bs4.element.Tag:
print("bs4_element_var's type is bs4.element.Tag")
if isinstance(bs4_element_var, bs4.element.Tag)
print("bs4_element_var's type is bs4.element.Tag")
您还必须将 与Tag
一起导入BeautifulSoup
:
from bs4 import BeautifulSoup, Tag
并检查您的元素是否为type()
Tag
:
if type(bs4_element_var) == Tag:
print("bs4_element_var's type is bs4.element.Tag")
if isinstance(bs4_element_var, Tag):
print("bs4_element_var's type is bs4.element.Tag")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句