可以通过设置BeautifulSoup的解析器来解决这个问题。例如,在使用lxml解析器时,可以在BeautifulSoup对象的初始化函数中添加参数'parser':'lxml',如下所示:
from bs4 import BeautifulSoup
html = """
Test Title
Hello world!
What's up?
"""
soup = BeautifulSoup(html, 'lxml', parser='lxml')
result = soup.find_all('p')
print(result)
输出结果为:
[Hello world!
, What's up?
]
可以看到,这样就可以正常显示所有数据了。