# BeautifulSoup

### BeautifulSoup

Used for small projects or quick tests

### Links:

* [Find All method](https://www.skytowner.com/explore/beautiful_soup_find_all_method)
* [Beautiful Soup: Build a Web Scraper With Python](https://realpython.com/beautiful-soup-web-scraper-python/)

### Packages:

* BeautifulSoup: This module is used for iterating, searching, and modifying the parse tree over the HTML or XML parser. To download it type the below command in the terminal.
* Requests: Requests library is one of the integral part of Python for making HTTP requests to a specified URL. To download it type the below command in the terminal.

```bash
pip install beautifulsoup4
pip install requests
```

Imports:

```python
import requests
from bs4 import BeautifulSoup
```

### Get the parent span from badges, find all top-level spans inside by using find\_all() with recursive=False:

```
from bs4 import BeautifulSoup

page = """<div class="badges">
<span>
    <span title="9 gold badges"><span class="badge1"></span><span class="badgecount">9</span></span>
    <span title="38 silver badges"><span class="badge2"></span><span class="badgecount">38</span></span>
    <span title="56 bronze badges"><span class="badge3"></span><span class="badgecount">56</span></span>
</span>
</div>"""
```

```
soup = BeautifulSoup(page)
badges = soup.body.find('div', attrs={'class': 'badges'})
for span in badges.span.find_all('span', recursive=False):
    print span.attrs['title']
```

#### prints:

`9 gold badges` `38 silver badges` `56 bronze badges`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.arkannis.net/programming/python/modules/webscraping/beautifulsoup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
