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

Encoding in Beautiful Soup


As already explained, every HTML/XML document will be written in a specific character set encoding, for example, UTF-8, and Latin-1. In an HTML page, this is represented using the meta tag as shown in the following example:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

Beautiful Soup uses the UnicodeDammit library to automatically detect the encoding of the document. Beautiful Soup converts the content to Unicode while creating soup objects from the document.

Note

Unicode is a character set, which is a list of characters with unique numbers. For example, in the Unicode character set, the number for the character B is 42. UTF-8 encoding is an algorithm that is used to convert these numbers into a binary representation.

In the previous example, Beautiful Soup converts the document to Unicode.

html_markup = """<p> The Spanish language is written using the Spanish alphabet, which is the Latin alphabet  with one additional letter, eñe ⟨ñ⟩...
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 R$50/month. Cancel anytime