我知道这个问题已经在这个网站上问了很多,但是我已经尝试了所有给出的解决方案,但是我不知道如何解决这个问题。
对于初学者:我在使用的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'
这是我尝试解决此问题的方法:
bs4
(import bs4
)。那工作得很好,或者至少不会导致任何错误。bs4
文件当前位于默认Anaconda
文件夹中。然后我改变了CD的项目文件的位置,甚至试图复制和粘贴bs4
,bs4-0.0.1.dist-info
以及beautifulsoup4-4.6.3.dist-info
文件添加到项目文件目录。那里什么都没有真正改变。pip3
安装了bs4
。我不知道这是否必要,但我也做到了。Anaconda
一次和bs4/beautifulsoup
7或8次,包括的一些使用pip install --upgrade -force-reinstall beautifulsoup4
。无论如何,我希望这有助于描述问题。让我知道是否可以提供更多信息。
预先感谢你们给我的任何帮助!
正如@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] 删除。
我来说两句