使用beauthoulsoup查找所有以给定

2024-04-23 17:57:57 发布

您现在位置:Python中文网/ 问答频道 /正文

如果要查找id=test with BeautifulSoup的所有<;p>;元素,我使用:

for item in soup.findAll('p', {"id": "test"}):

如何找到ID以特定字母开头的每个

元素,比如说“t”?在

我试过“不”,但没用。在


Tags: intestltgtid元素forwith
3条回答

尝试:

import re
for item in soup.findAll('p', {"id": re.compile('^t')}):
for item in soup.findAll('p', {"id": lambda x: x and x.startswith('t')}):

试试这个:

for item in soup.find_all('p', id=re.compile('^test')):

相关问题 更多 >