Web Data
Can use TouchDevelop to open web pages
page main () initialize do nothing display boxed "click me" → post to wall box → on tapped(handler) where handler() is web → browse( "https://www.roanoke.edu/inside" ) end end end boxed end page
- But that takes the user out of your app and into another app
- Sometimes you just want some of the information on a page
Touch develop can download a web page
page main () initialize ◳ web page := "" display boxed "click me" → post to wall box → on tapped(handler) where handler() is web → download( "https://www.roanoke.edu/inside" ) end end end boxed ◳ web page → post to wall end page
- But it doesn’t make much sense
- What is displayed is the web page’s source code
- Can find the text that is displayed among lots of other difficult to decipher text
- That additional text specifies how the web looks when it is displayed by the browser
We can get rid of all the parts we don’t want with a little extra work
String Parsing
- The web page we downloaded is just one large piece of text
We can extract portions of text
"this is some text" → substring(0, 3) → post to wall
- The numbers are the location of the start and the length
- Note, it counts from zero
- But we don’t always know exactly where the text we want is located
We can search for text to find it
"this is some text" → index of("some", 0) → post to wall
- The number is where to start from when searching
- If there is more than one occurance, it finds the first
So we can use this to find what’s for lunch
page main () initialize ◳ web page := web → download("https://www.roanoke.edu/inside") var start := web page → index of("Next Meal:", 0) var end := web page → index of("</h4>", start) var length := end - start ◳ next meal := ◳ web page → substring(start, length) display ◳ next meal → post to wall end page
Can also join pieces of text together
◳ next meal := "Result: " ∥ ◳ next meal