Python: Understanding scraping with Beautiful Soup ver. 2

Last Updated on May 15, 2022 by shibatau

I. Why don’t you use Pandas?

Web scraping seems difficult and Beautiful Soup might look confusing and difficult to use. Ok, let’s try to use Pandas and use DataFrame, which you are accustomed to.

You have to load and parse HTML and convert it to a table in the following procedures:

As you see, your table would be complex with very long column names to show the structures of the nested values. Now you would understand why we should use Beautifulsoup (Dictionaries + Objects + …) instead of data frames for the data with deeply nested structures.

You can see the sample codes here though they are not completed.

II. Using Beautiful soup

You can learn how to use Beautiful Soup here:

Tutorial: Web Scraping with Python Using Beautiful Soup

I have added some comments and functions for learners’ understanding. You can see the scripts here again:

Some notes:

Soup is an object created with Beautifulsoup and it has methods (functions) and attributes (data) shown below.


You can use the find_all function to get texts with tags. For example, you can get all the occurrences of the <p> TEXTS </p> with the code:


You can access the first object with the following code:

<p>Here is some simple content for this page.</p>

You can get just the texts between the tags with the get_text function:

'Here is some simple content for this page.'

If you are interested in Classes and Objects, my following post may help you get general understanding of Python Objects.

Python: Learning how to handle CSV data with DataFrame, Class and Dictionary, ver. 8

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.