Skip to content

An error message in python with bs4 #103166

@JokerDemonKing-bin

Description

@JokerDemonKing-bin
import bs4


html = '''
<title>小丑之家</title>
<div class="info" float="left">Welcome to Joker's home</div>
<div class='info' float='right'>
    <span>Good Good Study, Day Day Up</span>
    <a href='https://www.bilibili.com></a>
    <strong><!--无效--></strong>
</div>
'''

print("-------------获取内容-----------------")
print(soup.span.string)
print(soup.strong.string)
print(soup.strong.text)    # 用text无法获取注释信息

This is running in a general Python environment. The problem with the code above is that when <a href='https://www.bilibili.com'></a> is missing a single quote, running the Python code prompts an error that says print(soup.strong.string) 'NoneType' object has no attribute 'string', but completing the single quote does not result in this error. There is something wrong with the error here, I hope it can be corrected.
1
2

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions