在BeautifulSoup初始化时,设置参数features='lxml',可以避免标签被转换为小写字母。示例代码如下所示:
from bs4 import BeautifulSoup import requests
html_doc = """
The Dormouse's story
Once upon a time there were three little sisters; and their names were
Elsie,
Lacie and
Tillie;
and they lived at the bottom of a well.
...
"""
soup = BeautifulSoup(html_doc, features='lxml')
print(soup.prettify())