> For the complete documentation index, see [llms.txt](https://pedroaovieira.gitbook.io/thm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pedroaovieira.gitbook.io/thm/advent-of-cyber-ii/theres-a-python-in-my-stocking.md).

# There's a Python in my stocking!

## Video

{% embed url="<https://www.youtube.com/watch?v=lvcZRKO-B20>" %}

## Resources

`pip install X`

`pip3 install requests beautifulsoup4`

```python
# Import the libraries we downloaded earlier
# if you try importing without installing them, this step will fail
from bs4 import BeautifulSoup
import requests 

# replace testurl.com with the url you want to use.
# requests.get downloads the webpage and stores it as a variable
html = requests.get('testurl.com') 

# this parses the webpage into something that beautifulsoup can read over
soup = BeautifulSoup(html, "lxml")
# lxml is just the parser for reading the html 

# this is the line that grabs all the links # stores all the links in the links variable
links = soup.find_all('a href') 
for link in links:      
    # prints each link    
    print(link)
```

&#x20;This was a very short introduction to Python, but here are some more links if you wanted to learn more:

* [Python Zero to Hero](https://polymath.cloud/python/)
* [Python Moduluo Operator in Practice](https://realpython.com/python-modulo-operator/)
* [Automate the Boring Stuff with Python](https://automatetheboringstuff.com/)

## Challenge

### What's the output of True + True?

{% hint style="success" %}
2
{% endhint %}

### What's the database for installing other peoples libraries called?

{% hint style="success" %}
PyPi
{% endhint %}

### What is the output of bool("False")?

{% hint style="success" %}
True
{% endhint %}

### What library lets us download the HTML of a webpage?

{% hint style="success" %}
Requests
{% endhint %}

### What is the output of the program provided in "Code to analyse for Question 5" in today's material?

&#x20;(This code is located above the Christmas banner and below the links in the main body of this task)

{% hint style="success" %}
\[1, 2, 3, 6]
{% endhint %}

### What causes the previous task to output that?

{% hint style="success" %}
Pass by reference
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://pedroaovieira.gitbook.io/thm/advent-of-cyber-ii/theres-a-python-in-my-stocking.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.
