gpt4 book ai didi

python - PyCharm 无法导入 BeautifulSoup

转载 作者:太空宇宙 更新时间:2023-11-04 07:17:52 25 4
gpt4 key购买 nike

我试图在 Python 上使用 bs4 制作蜘蛛,我已经使用 pip 和 easy_install 安装了 bs4,但是一旦我使用 PyCharm 运行该程序,它就会出现错误:

Traceback (most recent call last):
File "C:/PyCharm Project/bs4.py", line 3, in <module>
from bs4 import BeautifulSoup
File "C:\PyCharm Project\bs4.py", line 3, in <module>
from bs4 import BeautifulSoup
ImportError: cannot import name 'BeautifulSoup'

Process finished with exit code 1

但是在cmd提示中并没有出现这个错误:

C:\WINDOWS\system32>python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup
>>>
>>> html_doc = """
... <html><head><title>The Dormouse's story</title></head>
... <body>
... <p class="title"><b>The Dormouse's story</b></p>
...
... <p class="story">Once upon a time there were three little sisters; and their names were
... <a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
... <a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
... <a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
... and they lived at the bottom of a well.</p>
...
... <p class="story">...</p>
... """
>>>
>>> # create a bs object using a HTML page
... soup = BeautifulSoup(html_doc, 'html.parser', from_encoding='utf-8')
>>> soup.title
<title>The Dormouse's story</title>
>>> soup.title.string
"The Dormouse's story"
>>>

项目翻译:

最佳答案

你调用了你的脚本 C:/PyCharm Project/bs4.py",使用 from bs4 import BeautifulSoup 你实际上是在尝试导入 BeautifulSoup 来自您自己的脚本而不是 bs4 库,因此您需要重命名它并删除目录中的所有 .pyc 文件。

关于python - PyCharm 无法导入 BeautifulSoup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34515649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com