python - ImportError:无法从“bs4.element”导入名称“样式表”
问题描述
我想在访问网站后获得一些链接。导入 BeautifulSoup 时出现以下错误。
Traceback (most recent call last):
File "e:/User/Python/CF.py", line 3, in <module>
from bs4 import BeautifulSoup
File "C:\Users\CP\AppData\Local\Programs\Python\Python38\lib\site-packages\bs4\__init__.py", line 29, in <module>
from .builder import builder_registry
File "C:\Users\CP\AppData\Local\Programs\Python\Python38\lib\site-packages\bs4\builder\__init__.py", line 7, in <module>
from bs4.element import (
ImportError: cannot import name 'Stylesheet' from 'bs4.element' (C:\Users\CP\AppData\Local\Programs\Python\Python38\lib\site-packages\bs4\element.py)
这是我安装它的方法。
pip install beautifulsoup4
然后 cd 到目录并运行Python setup.py install
我也试过重新安装它。
代码没什么大不了的。当我删除它时它工作正常from bs4 import BeautifulSoup
。
import requests
from bs4 import BeautifulSoup
URL = "https://www.facebook.com/"
r = requests.get(URL)
我还尝试将文件名从 Report.py 更改为 CF.py
解决方案
我认为python 3.8有问题。我对 Python3.8.6 有同样的问题。因此,您可以更改解释器或卸载 Python3.8 并安装另一个版本。
推荐阅读
- css - 网格列 B 项从网格列 A 项的最后一行开始
- r - R OSRM:doTryCatch 中的错误(return(expr),名称,parentenv,处理程序):找不到对象“res”
- javascript - whatsapp 上的元属性共享链接不起作用
- gcloud - gcloud 构建。
没有 storage.objects.get 访问 Google Cloud Storage 对象的权限 - discord.py - 忽略命令购买中的异常
- javascript - async&await 与普通的 Promise 有何不同?
- c# - 如何使用 C# 将 Azure 文件共享中的 CSV 文件读入内存流?
- c++ - Makefile 编译问题
- javascript - 你能创建一个通用的或假的滑动动作/触摸吗?
- c - C 相邻堆栈寻址