Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Work with the Library | Beautiful Soup
Web Scraping with Python (res)
course content

Зміст курсу

Web Scraping with Python (res)

Web Scraping with Python (res)

1. HTML Files and DevTools
2. Beautiful Soup
3. CSS Selectors/XPaths
4. Tables

Work with the Library

Regular expressions are great for matches but a bit inconvenient. Python provides us with an instrumental library for web scrapping - BeautifulSoup!

BeautifulSoup makes it easy to go through HTML files and extract the parts we are interested in. To import the library, use:

To create the first object and start iterating with the website, use the following code:

We assign the Beautiful Object to the variable soup with two parameters. The first one is the HTML file we want to parse. The second argument tells which parser to use. "html.parser" corresponds to Python's built-in HTML parser.

BeautifulSoup is highly comfortable to work with since you don't need to write regexes or additional conditions to extract the data from tags.

For instance, let's get the first tag of the type title from the website:

1
print(soup.title)
copy

BeautifulSoup can also help to convert websites into DataFrames (using pandas), which are easier to manipulate. We will learn how to do this in the following chapters.

Завдання

Print the first h1 of the page tag using BeautifulSoup:

  1. Import the needed library.
  2. Create the BeautifulSoup object and assign it to the variable soup.
  3. Print the first h1 tag using the variable soup.

Завдання

Print the first h1 of the page tag using BeautifulSoup:

  1. Import the needed library.
  2. Create the BeautifulSoup object and assign it to the variable soup.
  3. Print the first h1 tag using the variable soup.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 2. Розділ 1
toggle bottom row

Work with the Library

Regular expressions are great for matches but a bit inconvenient. Python provides us with an instrumental library for web scrapping - BeautifulSoup!

BeautifulSoup makes it easy to go through HTML files and extract the parts we are interested in. To import the library, use:

To create the first object and start iterating with the website, use the following code:

We assign the Beautiful Object to the variable soup with two parameters. The first one is the HTML file we want to parse. The second argument tells which parser to use. "html.parser" corresponds to Python's built-in HTML parser.

BeautifulSoup is highly comfortable to work with since you don't need to write regexes or additional conditions to extract the data from tags.

For instance, let's get the first tag of the type title from the website:

1
print(soup.title)
copy

BeautifulSoup can also help to convert websites into DataFrames (using pandas), which are easier to manipulate. We will learn how to do this in the following chapters.

Завдання

Print the first h1 of the page tag using BeautifulSoup:

  1. Import the needed library.
  2. Create the BeautifulSoup object and assign it to the variable soup.
  3. Print the first h1 tag using the variable soup.

Завдання

Print the first h1 of the page tag using BeautifulSoup:

  1. Import the needed library.
  2. Create the BeautifulSoup object and assign it to the variable soup.
  3. Print the first h1 tag using the variable soup.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 2. Розділ 1
toggle bottom row

Work with the Library

Regular expressions are great for matches but a bit inconvenient. Python provides us with an instrumental library for web scrapping - BeautifulSoup!

BeautifulSoup makes it easy to go through HTML files and extract the parts we are interested in. To import the library, use:

To create the first object and start iterating with the website, use the following code:

We assign the Beautiful Object to the variable soup with two parameters. The first one is the HTML file we want to parse. The second argument tells which parser to use. "html.parser" corresponds to Python's built-in HTML parser.

BeautifulSoup is highly comfortable to work with since you don't need to write regexes or additional conditions to extract the data from tags.

For instance, let's get the first tag of the type title from the website:

1
print(soup.title)
copy

BeautifulSoup can also help to convert websites into DataFrames (using pandas), which are easier to manipulate. We will learn how to do this in the following chapters.

Завдання

Print the first h1 of the page tag using BeautifulSoup:

  1. Import the needed library.
  2. Create the BeautifulSoup object and assign it to the variable soup.
  3. Print the first h1 tag using the variable soup.

Завдання

Print the first h1 of the page tag using BeautifulSoup:

  1. Import the needed library.
  2. Create the BeautifulSoup object and assign it to the variable soup.
  3. Print the first h1 tag using the variable soup.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Regular expressions are great for matches but a bit inconvenient. Python provides us with an instrumental library for web scrapping - BeautifulSoup!

BeautifulSoup makes it easy to go through HTML files and extract the parts we are interested in. To import the library, use:

To create the first object and start iterating with the website, use the following code:

We assign the Beautiful Object to the variable soup with two parameters. The first one is the HTML file we want to parse. The second argument tells which parser to use. "html.parser" corresponds to Python's built-in HTML parser.

BeautifulSoup is highly comfortable to work with since you don't need to write regexes or additional conditions to extract the data from tags.

For instance, let's get the first tag of the type title from the website:

1
print(soup.title)
copy

BeautifulSoup can also help to convert websites into DataFrames (using pandas), which are easier to manipulate. We will learn how to do this in the following chapters.

Завдання

Print the first h1 of the page tag using BeautifulSoup:

  1. Import the needed library.
  2. Create the BeautifulSoup object and assign it to the variable soup.
  3. Print the first h1 tag using the variable soup.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 2. Розділ 1
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt