Skip to main content

Section 14.14 You can download all the plans here

Subsection 14.14.1 Plan 1

Activity 14.14.1.

# Get the webpage
_____________________________________________

# Extract info from the page
_____________________________________________

# Do something with the info
_____________________________________________

Subsection 14.14.2 Plan 2

Activity 14.14.2.

# Load libraries for web scraping
from bs4 import BeautifulSoup
import requests
# Get a soup from a URL 
url = _________________________
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')

Subsection 14.14.3 Plan 3

Activity 14.14.3.

# Load libraries for web scraping
from bs4 import BeautifulSoup
import requests
# Get a soup from multiple URLs 
base_url = ___________________________________
endings =  ___________________________________
for ending in endings:
    url = base_url + ending 
    r = requests.get(url) 
    soup = BeautifulSoup(r.content, 'html.parser')

Subsection 14.14.4 Plan 4

Activity 14.14.4.

# Get first tag of a certain type from the soup
tag = soup.find(___________)
# Get info from the tag
info = tag.________

Subsection 14.14.5 Plan 5

Activity 14.14.5.

# Get all tags of a certain type from the soup
tags = soup.find_all(___________)
# Collect info from the tags
collect_info = []
for tag in tags:
    # Get info from tag
    info = tag.________
    collect_info.append(info)

Subsection 14.14.6 Plan 6

Activity 14.14.6.

# Get first tag of a certain type from the soup
first_tag = soup.find(___________)
# Get all tags of a certain type from the first tag
tags = first_tag.find_all(____________)
# Collect info from the tags
collect_info = []
for tag in tags: 
    # Get info from tag
    info = tag.________
    collect_info.append(info)

Subsection 14.14.7 Plan 9

Activity 14.14.7.

# Print info
print(____________)

Subsection 14.14.8 Plan 10

Activity 14.14.8.

# Load library for json files
import json
# Put info into file
f = open(____________, 'w')
json.dump(____________, f)
f.close()
You have attempted of activities on this page.