The Internet is full of information that you can use in your own programs. For example, imagine writing an
block that looks up the weather forecast for your location and tells you whether or not to carry an umbrella.
But weather forecast sites change the appearance of their pages from time to time, so we're going to start with a web site we control. We want a list of all the available libraries of Snap! blocks.
Sometimes you're lucky, and a URL points directly to a data file:
If you don't already have it open, load your project U4L1-web from the previous activity.
split
block in the Operators palette, and experiment with the different options for the second input slot.
Read the help screen (right-click on a split
block and choose "Help") if you need ideas.When you're not lucky, the information you want is buried in a mass of HTML code. Extracting the information from the formatting is called scraping the web page.
scrape
block in this project is an attempt to scrape just the file names from the libraries
web page. It almost works, but it has a couple of problems.
scrape
and make sure you understand how it works. It uses helper blocksscrape
so that you get a complete list of files and nothing else.scrape
block on snap.berkeley.edu/snapsource/Costumes to make sure it can work on any file directory. ("Directory" is the technical term for what users call a "folder": a collection of files.)