python - 当我尝试使用漂亮的汤打印标签时显示 IdentationError
问题描述
from bs4 import BeautifulSoup
with open('Home.html','r')as html_file:
content=html_file.read()
print(content)
soup = BeautifulSoup(content,'lxml')
tags = soup.find('h5') #error showing here
print(tags)#and here
谁能告诉我为什么从这里显示识别错误。请告诉我我必须安装哪个软件包或运行这个软件包我必须做什么样的事情。
解决方案
您不小心将 with 语句的前 4 行缩进了 1 个空格。
这是一个修复:
from bs4 import BeautifulSoup
with open('Home.html','r')as html_file:
content=html_file.read()
print(content)
soup = BeautifulSoup(content,'lxml')
tags = soup.find('h5')
print(tags)
推荐阅读
- git - git commit w/o message 后被困在 vim 调试窗口中
- python - 无法使用 yapf 设置/使用旋钮(谷歌的 Python 格式化程序)
- apache-camel - Weblogic 12.2 中的 Apache Camel LRUCacheFactory 死锁
- r - 如何重新排列行?
- reactjs - 使用多个 setHook 会使组件多次渲染?
- python-3.x - 始终处理但并不总是产生的生成器函数
- excel - 如果您连续更改单元格值,请添加标识符
- config - 强制重新加载 clickhouse 配置?
- xamarin.android - Xamarin.Android 在 MVVMCross 加载器中滑动以刷新无限加载
- kubernetes - 使用 Kubernetes 集群启动 Kubernetes Helm 图表