相关疑难解决方法(0)

在按复合类名称搜索时,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 ×1

html-parsing ×1

python ×1

python-2.7 ×1

regex ×1