使用bs4中的find_all函数筛选标签名为tr的标签,且对应的tr标签不含有class属性
时间: 2024-05-03 15:23:10 浏览: 10
可以使用以下代码来筛选标签名为tr且不含有class属性的标签:
```python
from bs4 import BeautifulSoup
html = """
<table>
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
<tr class="special">
<td>Row 3, Column 1</td>
<td>Row 3, Column 2</td>
</tr>
</table>
"""
soup = BeautifulSoup(html, 'html.parser')
trs = soup.find_all('tr', class_=False)
for tr in trs:
print(tr)
```
输出结果为:
```
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
```
在使用find_all函数时,可以通过class_参数来指定要筛选的标签的class属性值。如果将class_参数指定为False,则可以筛选不含有class属性的标签。