Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个:
dates = soup.findAll("div", {"id" : "date"})
但是,我需要 id 作为通配符搜索,因为idcandate_1等date_2。
id
date_1
date_2
您可以提供一个可调用对象作为过滤器:
dates = soup.findAll("div", {"id" : lambda L: L and L.startswith('date')})
或者正如@DSM 指出的那样
dates = soup.findAll("div", {"id" : re.compile('date.*')})
因为 BeautifulSoup 将识别 RegExp 对象并调用其.match()方法。
.match()