在Python中调用HTML文件通常有以下几种方法:
1. 使用`open()`函数读取本地HTML文件内容:
with open('example.html', 'r') as file:html_content = file.read()print(html_content)
2. 使用`requests`库获取网页内容,然后使用`BeautifulSoup`库解析HTML:
import requestsfrom bs4 import BeautifulSoup获取网页内容response = requests.get('http://www.zyiz.net/python/features.html')html_doc = response.text解析HTMLsoup = BeautifulSoup(html_doc, 'html.parser')格式化并打印HTML内容strhtm = soup.prettify()print(strhtm)
3. 使用`webbrowser`模块打开HTML文件:
import webbrowser打开HTML文件webbrowser.open('example.html')
请根据您的需求选择合适的方法。如果您需要进一步处理HTML内容,比如提取特定数据,可以使用`BeautifulSoup`库提供的各种方法和属性

