如何使用BeautifulGroup读取html标记

2024-10-05 13:25:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用beautifulsoap读取html标记,并检查是否有一些标记可用或丢失。在

我正在使用beauthoulsoup读取文件,然后在我的测试文件中使用它。在

在这里,我尝试了但没有成功:

class Testing(unittest.TestCase):
        @classmethod
        def setUp(name):

            name.html = None
            with open("index.html") as frd:
                name.html = frd.read()
                name.soup = BeautifulSoup(name.html)
            if not name.html:
                raise Exception('cant read')    

        def testing(self)
         assert self.soup.find('html') == 'html'
          #Raise : error

我在soup中找不到使用find()函数的html标记(尝试打印它以查看输出,但力不从心)。如果HTML文件中缺少HTML标记,如何引发异常?在


Tags: 文件name标记selfreaddefhtmlfind

热门问题