Fall 2026
  • Discord
  • Gradescope
  • Syllabus

On this page

  • Start
  • Extract and analyze
  • Check and submit

Lab: Web Data: Extract, Analyze, Visualize

Due: Wednesday, October 14 at 11:59pm · Worth: 16 points

Web scraping lets us collect data from a page without copying each item by hand. You’ll extract information from HTML, then analyze a saved archive of Donald Trump’s tweets and plot how often particular phrases appear.

Start

Download and extract the starter ZIP. Open the inner lab-web-data folder in VS Code, then initialize and publish your repository as lab-web-data. Activate a Python environment, then run:

python -m pip install -r requirements.txt
python download_tweets.py

The downloader saves ten master_*.json files from the 2009–2018 archive. Keep them in the repository’s top-level folder so your analysis script can find them.

Extract and analyze

Complete the selectors first, then the analysis script. Each part is graded separately. In addition to the five required searches, choose at least three phrases of your own. You can use the fictional slogans from sample_merchandise.html for ideas.

Extract listings

Complete the eight functions in lab_selectors.py. Their doctests specify inputs and results. Open sample_listings.html in your browser to check the records you extract. See the Beautiful Soup examples for selectors, text, and attributes.

  • Implement count_matches, select_texts, and select_attr, returning results in page order. Preserve text whitespace in select_texts.

  • Implement extract_titles with surrounding whitespace removed, and extract_prices_cents with integer prices in cents.

  • Implement count_free_shipping and first_link. Return None when there is no first link.

  • Implement extract_listings: return one dictionary per item with name, price_cents, and url, searching within that item.

Analyze the archive

Complete lab_tweets.py. Use the JSON example to load records and the bar-chart reference for plotting. The starter’s format_table.py demonstrates number formatting. All results must come from the input files, including when the grader supplies different tweets.

  • Load master_2009.json through master_2018.json and print the combined record count. Count duplicate records as stored.

  • Count tweets containing Obama, Trump, Mexico, Russia, and Fake News, ignoring capitalization. Use full_text when present, otherwise text. Count each tweet once per phrase.

  • Choose at least three additional phrases and compute their counts in the same way.

  • Generate a labeled bar chart from your calculated counts or percentages. Use the standard library and matplotlib for the analysis script.

  • Put a Markdown table in README.md with all eight or more phrases and their percentages. Right-align the phrase column and display percentages with two digits before and after the decimal, such as 07.73.

  • Write at least one sentence describing what your results show.

  • Save the chart as an image, commit it, and embed it using a local image link in the README.

Check and submit

Run:

python -m doctest lab_selectors.py
python lab_tweets.py

For the supplied archive, check the total of 35402 tweets, 13659 containing Trump, and 2738 containing Obama. Open the saved chart and confirm that the README displays both the table and image.

Commit and sync lab_selectors.py, lab_tweets.py, README.md, and the saved chart. On Gradescope, choose GitHub and submit lab-web-data and the branch containing your work. The submission guide explains resubmission.