Teacher's Choice

Reading HTML with Snap! (Teacher's Choice)

Tuesday, January 26, 2016 at 4:28 PM email on the edX "Calling Internet APIs" lab (you will need to log in with the EDC edX account; see Mary if you don't have the access, but it should be in your email from me on Thursday, March 10, 2016 at 6:13 PM). Here's a link to load the XML: BJCx_Internet_APIs.xml

The Internet is full of information that you can use in your programs.

For example, you could code an umbrella? predicate block that looks up the weather forecast for your location (based on your IP address) and tells you whether or not to carry an umbrella. Or you could build a current temperature block that reports the current temperature for the given location:
current temperature in (New York) reporting 34
  1. Talk with Your Partner Load this project, and click on the http:// (snap.berkeley.edu) block. What does the http block is report?
  2. Be sure not to include the "http://" in the input slot. That's already included as part of the http block.
    Don't include the 'http://' in the http block input slot.
  3. Open http://snap.berkeley.edu for reference. Can you find any correspondences between the actual webpage and the code that the http block reports?

You probably saw the page title (the text up at the very top of the browser window) but not much else that looks familiar. Like most web pages, this one starts with a specification of the page format (things like the margin space to the left and right of the page text); the actual contents of the page is further inside it.

There are two custom substring blocks included in this project that allow you to select subsections of a text string. (What we've been calling a "text" is also called a text string or just a string.) They each report only a portion of a string:

You can use these two blocks together to report a specific piece of text on the page.
substring of (substring of (http:// (snap.berkeley.edu)) starting with(You get a)) up to (</section>)
You get a broadly inviting programming language for kids and adults that’s *also* a platform for serious study of computer science. (See the <About> page for details.)

  1. Why is the word "also" in italics on the web site?
  2. What happens when you click on the word "examples" at the very top of the web page? Why?
  1. most recent version of Snap! reporter reporting Use the substring starting with and substring up to blocks to create a reporter that uses the output of http:// (snap.berkeley.edu) to create a most recent version of Snap! reporter.
    The word "Snap!", which comes just before the version number, occurs many times on the page. Find "<p>Snap<em>!</em>" then get the text after it.