BeautifulSoup

BeautifulSoup中的findfindAllnameattr参数,支持正则写法:

代码:

h1userSoupList = soup.findAll(name="h1", attrs={"class":re.compile(r"h1user(\s\w+)?")});

可以从html:

<div class="icon_col">
        <h1 class="h1user">crifan</h1>
        <h1 class="h1user test1">crifan 123</h1>
        <h1 class="h1user test2">crifan 456</h1>
</div>

搜到列表:

class="h1user"
class="h1user test1"
class="h1user test2"

results matching ""

    No results matching ""