Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Advanced Search | Beautiful Soup: Part II
Web Scraping with Python

Advanced SearchAdvanced Search

Certain HTML tags require mandatory attributes, such as the anchor tag necessitating the href attribute or <img> requiring the src attribute. If you are interested in a specific attribute, you can use the .get() method following .attrs. For example, let's retrieve all the src attributes of all <img> elements.

You may also encounter the id attribute, which is quite common and is used to distinguish elements under the same tag. If you are interested in specific attribute values, you can pass them as a dictionary (in the format attr_name: attr_value) as the parameter for .find_all() (immediately after specifying the tag you are searching for). For example, we are interested in only <div> elements with the class attribute set to 'box', or we are searching for the <p> element with an "id" attribute value of "id2".

We utilized the .find() method (instead of .find_all()) to retrieve the element with a specific id since the id is a unique identifier, and there cannot be more than one element with the same value. To ensure that we obtained only specific <div> elements, let's examine the classes that <div> elements have.

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

Секція 3. Розділ 5
course content

Зміст курсу

Web Scraping with Python

Advanced SearchAdvanced Search

Certain HTML tags require mandatory attributes, such as the anchor tag necessitating the href attribute or <img> requiring the src attribute. If you are interested in a specific attribute, you can use the .get() method following .attrs. For example, let's retrieve all the src attributes of all <img> elements.

You may also encounter the id attribute, which is quite common and is used to distinguish elements under the same tag. If you are interested in specific attribute values, you can pass them as a dictionary (in the format attr_name: attr_value) as the parameter for .find_all() (immediately after specifying the tag you are searching for). For example, we are interested in only <div> elements with the class attribute set to 'box', or we are searching for the <p> element with an "id" attribute value of "id2".

We utilized the .find() method (instead of .find_all()) to retrieve the element with a specific id since the id is a unique identifier, and there cannot be more than one element with the same value. To ensure that we obtained only specific <div> elements, let's examine the classes that <div> elements have.

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

Секція 3. Розділ 5
some-alt