Reputation: 67
I know this question has been asked a lot on this site, but I have tried all of the solutions given, and I cannot figure out how to solve this problem.
For starters: I am on a Windows 10
computer using Python 3.6
. I installed Anaconda
as my IDE.
I tried to install BeautifulSoup4
with pip
install beautifulsoup4
, but I got the
Requirement already satisfied
response.
The code I am trying to run is just
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'
Here is what I have tried to resolve this problem:
bs4
(import bs4
). That works perfectly fine, or at least it does not lead to any errors.bs4
file is currently in the default Anaconda
folder. I then changed the CD to the location of the project file and even tried copying and pasting the bs4
, bs4-0.0.1.dist-info
, and beautifulsoup4-4.6.3.dist-info
files into the project file directory. Nothing really changed there.pip3
install bs4
. I don't know if that's necessary, but I did that as well.Anaconda
once and bs4/beautifulsoup
7 or 8 times, including a few uses of pip install --upgrade -force-reinstall beautifulsoup4
.Anyways, I hope this helps describe the problem. Let me know if I can provide any further information.
Thanks in advance for any help you guys can give me!
Upvotes: 3
Views: 5194
Reputation: 61900
As @Blender mentioned is just 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'])
Output
Found the URL: some_url
Found the URL: another_url
The above code was taken as example from this question
Upvotes: 5