使用正则表达式按复合类名称搜索时,BeautifulSoup返回空列表.
例:
import re
from bs4 import BeautifulSoup
bs =
"""
<a class="name-single name692" href="www.example.com"">Example Text</a>
"""
bsObj = BeautifulSoup(bs)
# this returns the class
found_elements = bsObj.find_all("a", class_= re.compile("^(name-single.*)$"))
# this returns an empty list
found_elements = bsObj.find_all("a", class_= re.compile("^(name-single name\d*)$"))
Run Code Online (Sandbox Code Playgroud)
我需要课程选择非常精确.有任何想法吗?