1. 使用内置的`open()`函数读取HTML文件内容:
```python
with open('example.html', 'r') as file:
html_content = file.read()
print(html_content)
2. 使用`requests`库获取网页内容,然后使用`BeautifulSoup`库解析HTML:
```python
import requests
from bs4 import BeautifulSoup
获取网页内容
response = requests.get('http://example.com')
html_content = response.text
使用BeautifulSoup解析HTML
soup = BeautifulSoup(html_content, 'html.parser')
print(soup.prettify())
3. 使用`lxml`库解析HTML:
```python
from lxml import html
with open('example.html', 'r') as file:
html_content = file.read()
使用lxml解析HTML
tree = html.fromstring(html_content)
print(tree.xpath('//html/body/h1/text()'))
以上方法可以帮助你读取HTML文件的内容。如果你需要提取特定的HTML元素或内容,可以使用`BeautifulSoup`库提供的各种方法和属性。