Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using BeautifulSoup Library with Python

I'm following a tutorial on creating a map using Python and the Beautiful Soup library.

I have downloaded beautiful soup and the folder is called "beautifulsoup4-4.1.3". The contents of this folder are in the attached image.

During the tutorial I am given the following code to use to import my data and beautiful soup:

import csv
from BeautifulSoup import BeautifulSoup

Trouble is that there is no file called "beautiful soup" within the beautiful soup folder. I have also attached the error message I receive in the terminal.

How should I import beautiful soup when there is no file with that name? I tried simply changing the folders name to "beautiful soup". I did not expect that to work and I was right - it did not.

Any advice on how to proceed welcome?

enter image description here

beautiful soup directory

like image 460
Doug Fir Avatar asked Mar 07 '26 06:03

Doug Fir


1 Answers

You installed the BeautifulSoup library version 4, which has been renamed:

from bs4 import BeautifulSoup

If you want the old name and matching API, you need to install BeautifulSoup 3 instead:

easy_install BeautifulSoup

Note that since your tutorial is using from BeautifulSoup import BeautifulSoup it may not entirely work with the updated API of BeautifulSoup version 4. If you run into problems, take a look at the porting to BS4 section of the BeautifulSoup documentation to 'translate' BS 3 code to the 4 API.

like image 183
Martijn Pieters Avatar answered Mar 08 '26 20:03

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!