我希望从网站上获取两个值.它们存在于以下标记中:
<span class="sp starBig">4.1</span>
<span class="sp starGryB">2.9</span>
Run Code Online (Sandbox Code Playgroud)
我需要值sp starBig,sp starGryB.
我正在使用的findAll表达式是 -
soup.findAll('span', {'class': ['sp starGryB', 'sp starBig']}):
Run Code Online (Sandbox Code Playgroud)
代码执行时没有任何错误,但没有显示结果.
使用正则表达式按复合类名称搜索时,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)
我需要课程选择非常精确.有任何想法吗?