# 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?
2
What's the database for installing other peoples libraries called?
PyPi
What is the output of bool("False")?
True
What library lets us download the HTML of a webpage?
Requests
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)