ImportError:无法导入名称“ BeautifulSoup4”

特里·汤森

我知道这个问题已经在这个网站上问了很多,但是我已经尝试了所有给出的解决方案,但是我不知道如何解决这个问题。

对于初学者:我在使用的Windows 10计算机上Python 3.6我安装Anaconda为我的IDE。

我尝试使用installBeautifulSoup4进行pip安装beautifulsoup4,但是得到了

已经满足要求

响应。

我试图运行的代码仅仅是

from bs4 import BeautifulSoup4

to which I get the error: ImportError: cannot import name 'BeautifulSoup4' 

The full error is:
runfile('C:/Users/ter/.spyder-py3/untitled1.py', wdir='C:/Users/ter/.spyder-py3')
Traceback (most recent call last):

  File "<ipython-input-21-8717178e85e1>", line 1, in <module>
    runfile('C:/Users/ter/.spyder-py3/untitled1.py', wdir='C:/Users/ter/.spyder-py3')

  File "C:\Users\ter\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\Users\ter\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/ter/.spyder-py3/untitled1.py", line 8, in <module>
    from bs4 import BeautifulSoup4

ImportError: cannot import name 'BeautifulSoup4' 

这是我尝试解决此问题的方法:

    1.由于我发现90%的解决方案是因为有人将文件命名为bs4.py,因此我进行了检查。但这是我在这台计算机上制作的第一个文件,名为“ untitled1.py”。后来(我做的最后一件事)出于沮丧,我从计算机上删除了每个bs4漂亮的实例,问题仍然存在,因此另一个名为“ bs4”的文件绝对不是问题。
  1. 我尝试仅导入bs4(import bs4)。那工作得很好,或者至少不会导致任何错误。
  2. 我改变了周围的目录。bs4文件当前位于默认Anaconda文件夹中。然后我改变了CD的项目文件的位置,甚至试图复制和粘贴bs4bs4-0.0.1.dist-info以及beautifulsoup4-4.6.3.dist-info文件添加到项目文件目录。那里什么都没有真正改变。
  3. 我也pip3安装了bs4我不知道这是否必要,但我也做到了。
  4. 我将所有这些安装了多次,包括Anaconda一次和bs4/beautifulsoup7或8次,包括的一些使用pip install --upgrade -force-reinstall beautifulsoup4

无论如何,我希望这有助于描述问题。让我知道是否可以提供更多信息。

预先感谢你们给我的任何帮助!

丹妮·梅塞乔(Dani Mesejo)

正如@Blender所说的只是BeautifulSoup:

from bs4 import BeautifulSoup

html = '''<a href="some_url">next</a>
<span class="class"><a href="another_url">later</a></span>'''

soup = BeautifulSoup(html)

for a in soup.find_all('a', href=True):
    print("Found the URL:", a['href'])

输出量

Found the URL: some_url
Found the URL: another_url

上面的代码以该问题为例

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

从bs4导入BeautifulSoup4

ImportError:无法导入名称'BeautifulSoup',已经安装的bs4

无法使用BeautifulSoup4抓取网站

未使用beautifulsoup4定义的名称错误'html'

无法从 BeautifulSoup4 中的字符串解析“href”

BeautifulSoup4无法从表中抓取数据

BeautifulSoup4无法从此表中抓取数据

无法在Mac OS上的python中安装beautifulsoup4

BeautifulSoup4无法通过搜索文本找到“ a”标签

在PyCharm中“未解决”导入bs4或BeautifulSoup4。安装很好

Beautifulsoup4导入错误:没有名为bs4的模块

Pyspark(spark 1.6.x)ImportError:无法导入名称Py4JJavaError

安装pgAdmin4时出现“ ImportError:无法导入名称'ImmutableDict'”错误

带有类别名称的表的Python scrape网站w / BeautifulSoup4 shwoing属性错误

如何从beautifulsoup4中的标签获取名称空间信息?

ImportError:无法导入名称

ImportError:无法导入名称

使用BeautifulSoup4和Python3.x无法通过HTML解析理解403错误

无法使用BeautifulSoup4(初学者)抓取正确的Wikitable

为什么我无法在Jupyterlab中使用BeautifulSoup4解析本地文件

无法使用BeautifulSoup4(Python 3)刮擦特定的表

BeautifulSoup4 python3.6 无法获取屏幕中间的数据

BeautifulSoup4表

如何使用Beautifulsoup4检查父标记是否具有名称不是“ div”的直接子代

ImportError:无法导入名称NullHandler

ImportError:无法导入名称“ IsolationForest”

ImportError:无法导入名称换行

ImportError:无法导入名称模式

ImportError:无法导入名称PunktWordTokenizer