There's a Python in my stocking!

Scripting

Video

Resources

pip install X

pip3 install requests beautifulsoup4

# 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)

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

Challenge

What's the output of True + True?

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

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

What library lets us download the HTML of a webpage?

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

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

What causes the previous task to output that?

Last updated

Was this helpful?