Find All!
We can also use the function .find_all()
to find not only one but multiple tags using a list. For instance:
1print(soup.find_all(["title","h1"]))
The code above returns the list of all title
and h1
tags in our HTML file.
We can also use functions as an argument to find:
123def find_all_condition(tag): return tag.string == "City: New York" print(soup.find_all(find_all_condition))
The code returns all tags which contain only the text "City: New York"
.
If you feel uncomfortable with functions in Python, repeat them with the course.
The BeautifulSoup
library can optimize work and save a lot of time extracting the data from web pages. However, sometimes even such a magic tool can't detect the needed information. In such cases, parse the needed information with the function .find()
and regular expressions!
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Запитайте мені питання про цей предмет
Сумаризуйте цей розділ
Покажіть реальні приклади
Awesome!
Completion rate improved to 4.76
Find All!
Свайпніть щоб показати меню
We can also use the function .find_all()
to find not only one but multiple tags using a list. For instance:
1print(soup.find_all(["title","h1"]))
The code above returns the list of all title
and h1
tags in our HTML file.
We can also use functions as an argument to find:
123def find_all_condition(tag): return tag.string == "City: New York" print(soup.find_all(find_all_condition))
The code returns all tags which contain only the text "City: New York"
.
If you feel uncomfortable with functions in Python, repeat them with the course.
The BeautifulSoup
library can optimize work and save a lot of time extracting the data from web pages. However, sometimes even such a magic tool can't detect the needed information. In such cases, parse the needed information with the function .find()
and regular expressions!
Дякуємо за ваш відгук!