Data123
Data123

Reputation: 33

Using BeautifulSoup for extracting text from webpage

I am new to Python programming I just installed Python (Version 3.5.2) and I am using Geany editor to write and execute my scripts.

I just tried this simple script but it is failing:

from bs4 import BeautifulSoup
import urllib
r = urllib.urlopen('http://www.aflcio.org/Legislation-and-Politics/Legislative-Alerts').read()
soup = BeautifulSoup(r)

Error:

Traceback (most recent call last):
  File "soup.py", line 1, in <module>
    from bs4 import BeautifulSoup
ImportError: No module named 'bs4'

I have installed BeautifulSoup using pip install bs4 and I get the successful output "Successfully installed bs4-0.0.1"

I understand this is a simple issue but any help would be appreciated!

Upvotes: 1

Views: 163

Answers (2)

jarcobi889
jarcobi889

Reputation: 845

Type "pip freeze" into the command line/terminal. If you don't see bs4-0.0.1 in that list, it isn't installed.

If you do see it, you could try "pip uninstall bs4" then reinstall "pip install bs4".

Also, remember that "pip install" is a command line/terminal command. You don't type it into the Python interpreter: you type it into the command line

Upvotes: 1

Danielle M.
Danielle M.

Reputation: 3682

The error means your interpreter can't find bs4. If you ran pip install bs4, try the following:

pip3 install bs4

pip3 is the Python3 specific pip. This answer doesn't apply on all platforms but you didn't provide yours :)

Upvotes: 2

Related Questions