Beautiful Soup 的 has_attr(~)
方法返回 Boolean
指示元素是否包含特定屬性。
例子
考慮以下 HTML:
my_html = """
<p id="person_one">Alex</p>
<p id="person_two">Bob</p>
<p id="person_three">Cathy</p>
"""
soup = BeautifulSoup(my_html)
要檢查第一個 <p>
標記是否具有 id
屬性:
soup.find("p").has_attr("id")
True
要檢查第一個 <p>
標記是否具有 age
屬性:
soup.find("p").has_attr("age")
False
相關用法
- Python hashlib.sha3_256()用法及代碼示例
- Python hasattr方法用法及代碼示例
- Python hashlib.sha3_512()用法及代碼示例
- Python hashlib.shake_256()用法及代碼示例
- Python hashlib.shake_128()用法及代碼示例
- Python hashlib.blake2s()用法及代碼示例
- Python hashlib.blake2b()用法及代碼示例
- Python hasattr()用法及代碼示例
- Python hash()用法及代碼示例
- Python hashlib.sha3_224()用法及代碼示例
- Python hashlib.pbkdf2_hmac用法及代碼示例
- Python hashlib.sha3_384()用法及代碼示例
- Python statistics harmonic_mean()用法及代碼示例
- Python OpenCV haveImageReader()用法及代碼示例
- Python help()用法及代碼示例
- Python NumPy hstack方法用法及代碼示例
- Python http.HTTPStatus用法及代碼示例
- Python help方法用法及代碼示例
- Python NumPy hypot方法用法及代碼示例
- Python html.escape()用法及代碼示例
- Python html.unescape()用法及代碼示例
- Python math hypot()用法及代碼示例
- Python hex方法用法及代碼示例
- Python hex()用法及代碼示例
- Python NumPy hsplit方法用法及代碼示例
注:本文由純淨天空篩選整理自Arthur Yanagisawa大神的英文原創作品 BeautifulSoup | has_attr method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。