相关疑难解决方法(0)

在Python中查找span标记内的多个属性

我希望从网站上获取两个值.它们存在于以下标记中:

<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)

代码执行时没有任何错误,但没有显示结果.

python beautifulsoup

7
推荐指数
1
解决办法
7090
查看次数

在按复合类名称搜索时,BeautifulSoup返回空列表

使用正则表达式按复合类名称搜索时,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)

我需要课程选择非常精确.有任何想法吗?

python regex beautifulsoup html-parsing python-2.7

5
推荐指数
1
解决办法
1649
查看次数

标签 统计

beautifulsoup ×2

python ×2

html-parsing ×1

python-2.7 ×1

regex ×1