[ Download | Documentation | Hall of Fame | For enterprise | Source | Changelog | Discussion group | Zine ]
You didn't write that awful page. You're just trying to get somedata out of it. Beautiful Soup is here to help. Since 2004, it's beensaving programmers hours or days of work on quick-turnaroundscreen scraping projects.
Web scraping is a very powerful tool to learn for any data professional. With web scraping the entire internet becomes your database. In this tutorial we sho. Web scraping with Python often requires no more than the use of the Beautiful Soup module to reach the goal. Beautiful Soup is a popular Python library that makes web scraping by traversing the DOM (document object model) easier to implement.
Beautiful Soup is a Python library designed for quick turnaroundprojects like screen-scraping. Three features make it powerful:
- Beautiful Soup provides a few simple methods and Pythonic idiomsfor navigating, searching, and modifying a parse tree: a toolkit fordissecting a document and extracting what you need. It doesn't takemuch code to write an application
- Beautiful Soup automatically converts incoming documents toUnicode and outgoing documents to UTF-8. You don't have to thinkabout encodings, unless the document doesn't specify an encoding andBeautiful Soup can't detect one. Then you just have to specify theoriginal encoding.
- Beautiful Soup sits on top of popular Python parsers like lxml and html5lib, allowing youto try out different parsing strategies or trade speed forflexibility.
Beautiful Soup parses anything you give it, and does the treetraversal stuff for you. You can tell it 'Find all the links', or'Find all the links of class externalLink', or 'Find all thelinks whose urls match 'foo.com', or 'Find the table heading that'sgot bold text, then give me that text.'
Valuable data that was once locked up in poorly-designed websitesis now within your reach. Projects that would have taken hours takeonly minutes with Beautiful Soup.
Interested? Read more.
Getting and giving support
If you have questions, send them to the discussiongroup. If you find a bug, file it on Launchpad. If it's a security vulnerability, report it confidentially through Tidelift.
Web Scraping Free
If you use Beautiful Soup as part of your work, please consider a Tidelift subscription. This will support many of the free software projects your organization depends on, not just Beautiful Soup.
If Beautiful Soup is useful to you on a personal level, you might like to read Tool Safety, a short zine I wrote about what I learned about software development from working on Beautiful Soup. Thanks!
Download Beautiful Soup
The current release is Beautiful Soup4.9.3 (October 3, 2020). You can install Beautiful Soup 4 withpip install beautifulsoup4
.
In Debian and Ubuntu, Beautiful Soup is available as thepython-bs4
package (for Python 2) or thepython3-bs4
package (for Python 3). In Fedora it'savailable as the python-beautifulsoup4
package.
Beautiful Soup is licensed under the MIT license, so you can alsodownload the tarball, drop the bs4/
directory into almostany Python application (or into your library path) and start using itimmediately. (If you want to do this under Python 3, you will need tomanually convert the code using 2to3
.)
Beautiful Soup 4 works on both Python 2 (2.7+) and Python3. Support for Python 2 will be discontinued on or after December 31,2020—one year after the Python 2 sunsetting date.
Beautiful Soup 3
Beautiful Soup 3 was the official release line of Beautiful Soupfrom May 2006 to March 2012. It does not support Python 3 and it willbe discontinued on or after December 31, 2020—one year after thePython 2 sunsetting date. If you have any active projects usingBeautiful Soup 3, you should migrate to Beautiful Soup 4 as part ofyour Python 3 conversion.
Here'sthe Beautiful Soup 3 documentation.
The current and hopefully final release of Beautiful Soup 3 is 3.2.2 (October 5,2019). It's the BeautifulSoup
package on pip. It's alsoavailable as python-beautifulsoup
in Debian and Ubuntu,and as python-BeautifulSoup
in Fedora.
Once Beautiful Soup 3 is discontinued, these package names will be available for use by a more recent version of Beautiful Soup.
Web Scraping Python Tutorial Beautiful Soup
Beautiful Soup 3, like Beautiful Soup 4, is supported through Tidelift.
Hall of Fame
Over the years, Beautiful Soup has been used in hundreds ofdifferent projects. There's no way I can list them all, but I want tohighlight a few high-profile projects. Beautiful Soup isn't what makesthese projects interesting, but it did make their completion easier:
- 'Movable Type', a work of digital art on display in the lobby of the New York Times building, uses Beautiful Soup to scrape news feeds.
- Jiabao Lin's DXY-COVID-19-Crawleruses Beautiful Soup to scrape a Chinese medical site for informationabout COVID-19, making it easier for researchers to track the spreadof the virus. (Source: 'How open source software is fighting COVID-19')
- Reddit uses Beautiful Soup to parsea page that's been linked to and find a representative image.
- Alexander Harrowell uses Beautiful Soup to track the business activities of an arms merchant.
- The developers of Python itself used Beautiful Soup to migrate the Pythonbug tracker from Sourceforge to Roundup.
- The Lawrence Journal-Worlduses Beautiful Soup to gatherstatewide election results.
- The NOAA's ForecastApplications Branch uses Beautiful Soup in TopoGrabber, a script fordownloading 'high resolution USGS datasets.'
If you've used Beautiful Soup in a project you'd like me to knowabout, please do send email to me or the discussiongroup.
Development
Development happens at Launchpad. You can get the sourcecode or filebugs.
Beautiful Soup Tutorial
This document (source) is part of Crummy, the webspace of Leonard Richardson (contact information). It was last modified on Saturday, October 03 2020, 15:42:16 Nowhere Standard Time and last built on Sunday, April 25 2021, 10:00:02 Nowhere Standard Time.
| Document tree:
|