使用正则表达式按复合类名称搜索时,BeautifulSoup返回空列表.
例:
import re from bs4 import BeautifulSoup bs = """ Example Text """ 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*)$"))
我需要课程选择非常精确.有任何想法吗?