Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with Beautiful Soup

You're reading from   Getting Started with Beautiful Soup Learn how to extract information from websites using Beautiful Soup and the Python urllib2 module. This practical, hands-on guide covers everything you need to know to get a head start in website scraping.

Arrow left icon
Product type Paperback
Published in Jan 2014
Publisher Packt
ISBN-13 9781783289554
Length 130 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Vineeth G Nair Vineeth G Nair
Author Profile Icon Vineeth G Nair
Vineeth G Nair
Arrow right icon
View More author details
Toc

Unformatted printing


Beautiful Soup supports the plain printing of the BeautifulSoup and Tag objects. This will return only the plain string without any formatting.

This can be done by using the str() or the unicode() method.

If we use the str() method on the BeautifulSoup or the Tag object, we get a normal Python string, shown as follows:

print(str(soup))

#output
'<html><body><p class="ecopyramid"></p><ul id="producers"><li class="producerlist"><div class="name">plants</div><div class="number">100000</div></li><li class="producerlist"><div class="name">algae</div><div class="number">100000</div></li></ul></body></html>'

We can use the encode() method that we used in Chapter 6, Encoding Support in Beautiful Soup, to encode the output in a specific encoding format.

We can use the decode() function on the BeautifulSoup or Tag object to get the Unicode string.

print(soup.decode...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime