Lesson 8 of 18
Downloading a Web Page & Using Literal Variables
In this lesson
Roy Osherove takes the input from the web with an HTTP get file action that accepts redirects and saves cnn.com to a file. The replacement then fails with could not expand replacement string, because FinalBuilder (external link, opens in new tab) tries to expand the percent signs in the downloaded HTML as variables, and an exclamation mark before the variable name tells it to read the value without parsing it.
Transcript
[00:02] (external link, opens in new tab) Okay, let's make things a bit more interesting now instead of having those important files here in this folder. Let's let's get those important inputs directly from the web. So, let's try to download a file from the web. So, one way to do it is http get file. So, I'm just searching in the top for http. I got this. Let's try to download directly cnn.com.
[00:38] (external link, opens in new tab) And if I just leave this unchecked, cnna.com has a redirect going on when you just load it. So I'm going to say accept redirects and process the final HTML file that you get. And I'm going to save this to a file called important CNN.com.txt. And of course the location of the file will be full path generation slash the name of the file
[01:09] (external link, opens in new tab) And I override it just in case. So now what happens if I just try to do this and of course I want to move this up so it happens before I define the file set. So let's try to run this and see what happens. seems to download the file and then there is an interesting error could not expand replacement string. Now this error seems a bit strange but what we have to understand is that this is
[01:39] (external link, opens in new tab) A part that we have to we have to realize might happen every once in a while. Inside vall input there is an HTML string. How do I know? Well, we can of course debug. We can also take a look at the important of CNN.com which is right here. And inside we have a bunch of HTML that we've downloaded. If we look around, we'll look for percent sign. And there are plenty of percent signs over here for example.
[02:09] (external link, opens in new tab) And the problem is that when you tell FinalBuilder to replace stuff from this, it also looks and finds percent signs inside the value and then it tries to expand them as if they're input variables or anything. And there might be an unclosed percent sign somewhere because obviously it's HTML. It's not designed for FinalBuilder. So we can tell FinalBuilder to ignore and not try to expand the value inside here just by saying
[02:40] (external link, opens in new tab) A exclam an exclamation mark before the name of the variable. So this means read the value in and don't try to parse the inside of the variable. So now if we try to do the same thing again, we'll see that now this works.