美化组不读取错误格式的htm

2024-04-26 00:07:01 发布

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

我在学美体。它没有正确地阅读一些网站。我发现原因是一些html属性格式错误。例如:

from bs4 import BeautifulSoup

html = """
        <html>
        <head><title>Test</title></head>
        <body>
        <p id="paraone"align="center">some content <b>para1</b>.<!--there is no space before 'align' attribute -->
        <p id="paratwo" align="blah">some content <b>para2</b>
        </html>
    """
soup = BeautifulSoup(html)
print "soup:", soup

我认为我的设计不是为了美化html。如果是这样的话,有没有其他模块来读取上面给定的html?我们不能解析格式错误的网站吗?在


Tags: id属性title网站html格式错误原因