py4e-int
Search
Table of Contents
Book Index
User
Course Home
Assignments
Practice
Peer Instruction (Instructor)
Peer Instruction (Student)
Change Course
Instructor's Page
Progress Page
Edit Profile
Change Password
Register
Login
Dark Mode
Scratch Activecode
Help
FAQ
Instructors Guide
About Runestone
Report A Problem
This Chapter
Write Code Questions
Mixed-Up Code Questions
Write Code Questions
14.1 Scrape all the Cottage Inn Pizza locations
14.2 Get news links from faculty webpages
14.3 Plan 2: Get a soup from a URL
14.4 Plan 3: Get a soup from multiple URLs
14.5 Plan 4: Get info from a single tag
14.6 Plan 5: Get info from all tags of a certain type
14.7 Plan 9: Print info
14.8 Plan 10: Store info in a json file
14.9 Code writing activity part 1
14.10 Code writing activity part 2
14.11 Code writing activity part 3
14.12 Code debugging activity
14.13 Code explaining activity
14.14 You can download all the plans here
14.15 Multiple Choice Questions
14.16 Mixed-Up Code Questions
14.17 Write Code Questions
14.14.
You can download all the plans here
¶
14.14.1.
Plan 1
¶
# Get the webpage _____________________________________________ # Extract info from the page _____________________________________________ # Do something with the info _____________________________________________
14.14.2.
Plan 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')
14.14.3.
Plan 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')
14.14.4.
Plan 4
¶
# Get first tag of a certain type from the soup tag = soup.find(___________) # Get info from the tag info = tag.________
14.14.5.
Plan 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)
14.14.6.
Plan 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)
14.14.7.
Plan 9
¶
# Print info print(____________)
14.14.8.
Plan 10
¶
# 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