Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Find/Find_all | 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

Find/Find_all

BeautifulSoup offers methods for going through HTML tags. One of them is the function .find(). It returns the first tag which matches the parameter or None if there are no matches:

12
print(soup.find("p")) print(soup.find("h9"))
copy

We will get the same result by accessing tags directly from the BeautifulSoup object: ​​print(soup.p).

To receive the list of all occurrences of the particular tag, we can use the built-in function of the BeautifulSoup object .find_all():

It returns the list of instances of the tag object provided by BeautifulSoup. Tag objects offer a comfortable interface to work with their contents.

One of the most important functions of BeautifulSoup is the ability to find the specific types of tags using their attributes:

12
print(soup.find_all("p", id = "id2")) print(soup.find_all(attrs = {"class":"afterbanner", "id": "id1"}))
copy

The functions .find() and .find_all() are more convenient in usage as they can work in combination with attributes and regexes.

Using scraping, you are always interested in a specific part of the website, and unique attributes can help to identify them.

Завдання

In this task, you will work with the following page.

  1. Create the BeautifulSoup object using as parameters html and "html.parser".
  2. Print the first div tag using the function .find() of the object soup.
  3. Print the p tag where the id equal to "id0" using the function .find_all() of the soup oblect.

Завдання

In this task, you will work with the following page.

  1. Create the BeautifulSoup object using as parameters html and "html.parser".
  2. Print the first div tag using the function .find() of the object soup.
  3. Print the p tag where the id equal to "id0" using the function .find_all() of the soup oblect.

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

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

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

Find/Find_all

BeautifulSoup offers methods for going through HTML tags. One of them is the function .find(). It returns the first tag which matches the parameter or None if there are no matches:

12
print(soup.find("p")) print(soup.find("h9"))
copy

We will get the same result by accessing tags directly from the BeautifulSoup object: ​​print(soup.p).

To receive the list of all occurrences of the particular tag, we can use the built-in function of the BeautifulSoup object .find_all():

It returns the list of instances of the tag object provided by BeautifulSoup. Tag objects offer a comfortable interface to work with their contents.

One of the most important functions of BeautifulSoup is the ability to find the specific types of tags using their attributes:

12
print(soup.find_all("p", id = "id2")) print(soup.find_all(attrs = {"class":"afterbanner", "id": "id1"}))
copy

The functions .find() and .find_all() are more convenient in usage as they can work in combination with attributes and regexes.

Using scraping, you are always interested in a specific part of the website, and unique attributes can help to identify them.

Завдання

In this task, you will work with the following page.

  1. Create the BeautifulSoup object using as parameters html and "html.parser".
  2. Print the first div tag using the function .find() of the object soup.
  3. Print the p tag where the id equal to "id0" using the function .find_all() of the soup oblect.

Завдання

In this task, you will work with the following page.

  1. Create the BeautifulSoup object using as parameters html and "html.parser".
  2. Print the first div tag using the function .find() of the object soup.
  3. Print the p tag where the id equal to "id0" using the function .find_all() of the soup oblect.

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

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

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

Find/Find_all

BeautifulSoup offers methods for going through HTML tags. One of them is the function .find(). It returns the first tag which matches the parameter or None if there are no matches:

12
print(soup.find("p")) print(soup.find("h9"))
copy

We will get the same result by accessing tags directly from the BeautifulSoup object: ​​print(soup.p).

To receive the list of all occurrences of the particular tag, we can use the built-in function of the BeautifulSoup object .find_all():

It returns the list of instances of the tag object provided by BeautifulSoup. Tag objects offer a comfortable interface to work with their contents.

One of the most important functions of BeautifulSoup is the ability to find the specific types of tags using their attributes:

12
print(soup.find_all("p", id = "id2")) print(soup.find_all(attrs = {"class":"afterbanner", "id": "id1"}))
copy

The functions .find() and .find_all() are more convenient in usage as they can work in combination with attributes and regexes.

Using scraping, you are always interested in a specific part of the website, and unique attributes can help to identify them.

Завдання

In this task, you will work with the following page.

  1. Create the BeautifulSoup object using as parameters html and "html.parser".
  2. Print the first div tag using the function .find() of the object soup.
  3. Print the p tag where the id equal to "id0" using the function .find_all() of the soup oblect.

Завдання

In this task, you will work with the following page.

  1. Create the BeautifulSoup object using as parameters html and "html.parser".
  2. Print the first div tag using the function .find() of the object soup.
  3. Print the p tag where the id equal to "id0" using the function .find_all() of the soup oblect.

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

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

BeautifulSoup offers methods for going through HTML tags. One of them is the function .find(). It returns the first tag which matches the parameter or None if there are no matches:

12
print(soup.find("p")) print(soup.find("h9"))
copy

We will get the same result by accessing tags directly from the BeautifulSoup object: ​​print(soup.p).

To receive the list of all occurrences of the particular tag, we can use the built-in function of the BeautifulSoup object .find_all():

It returns the list of instances of the tag object provided by BeautifulSoup. Tag objects offer a comfortable interface to work with their contents.

One of the most important functions of BeautifulSoup is the ability to find the specific types of tags using their attributes:

12
print(soup.find_all("p", id = "id2")) print(soup.find_all(attrs = {"class":"afterbanner", "id": "id1"}))
copy

The functions .find() and .find_all() are more convenient in usage as they can work in combination with attributes and regexes.

Using scraping, you are always interested in a specific part of the website, and unique attributes can help to identify them.

Завдання

In this task, you will work with the following page.

  1. Create the BeautifulSoup object using as parameters html and "html.parser".
  2. Print the first div tag using the function .find() of the object soup.
  3. Print the p tag where the id equal to "id0" using the function .find_all() of the soup oblect.

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