Placeholder Image

字幕表 動画を再生する

  • What's going on?

  • Everybody, welcome apart.

  • 10 of the Golan Tutorial series in this part we're really doing is the working on the first step to our news aggregator Web app thing, which is in orderto aggregate news, we first need to be able to access that news.

  • So to do that, we have to be able to read information from the Internet, which is actually a pretty common task.

  • So that's what we're gonna be covering here is how do we actually just pull down data from the Internet?

  • So that's what we're gonna D'oh!

  • I'm going to be pulling data from the Washington Post site map index, but you could use any web site you want to use.

  • Um, I'm just gonna be using that one.

  • I'll put a link to that in the description.

  • Either do that or the text based right up, which will have that link.

  • If I forget to do that, someone like holler at me.

  • Sorry, but, um, you really can use, like, any website.

  • So, uh, without going get started, I'm gonna go ahead and kind of clean up.

  • I'm gonna leave the main function, and then we can leave for Matt and also met a sheep because we're gonna be using both of those.

  • So, uh, now we're gonna go ahead and do Is everything pretty much for this one?

  • At least we'll waken contained within the main function.

  • So I'm just gonna tap over, and the first thing we want to do is get information from the Internet.

  • So So generally what's gonna happen?

  • And we kind of talked about this with, like, the web app, right?

  • Because we're kind of doing it.

  • You know, we're on both sides of this equation here, So if we want to pull information from a web site, we have to first make that request, and then we get a response.

  • And in general, that response is gonna have, you know, like a whole bunch of information.

  • But it will also have, like, you know, this stuff that your browser is going to use to render the website to your page.

  • So it's gonna have, like, that source code, But generally that's gonna be in bites, so we're gonna need it.

  • Convert that out to a string so we can actually, like, use it how we would like to, uh and then from there At least in our case, we we've got quite a bit of parsing and formatting that we need to be able to do from there.

  • But at least for the purpose of this tutorial, we're just gonna try to pull down that source code.

  • So let's go ahead and do that.

  • So, um, let's see, we're going to use format.

  • We're gonna use Net Http on then we also need to use the IOU till, so that's gonna be a Iot.

  • So lash, I owe you till.

  • So, um now what?

  • We're gonna go ahead and Dio is first, we're gonna make a request.

  • So the request is gonna return two things.

  • Basically, it's gonna be a response, and then it's gonna be an error if you're going if you get an error so it might be empty.

  • But for now, we're gonna use the underscore.

  • So you're just gonna use the underscore any time?

  • Don't forget, Colon equals anyway, you're gonna use underscore anytime you define a variable that you don't intend to use if you don't use the underscore basically just says, Okay, this is just throw away.

  • Something needs to be unpacked to this, but I don't plan to use it because in go, if you define a variable and then you don't use it, you're gonna get an error.

  • When when you run this script anyway, http dot get capital G again.

  • Exported.

  • Uh, we're gonna read in the link.

  • I'm just gonna copy and paste it, but, uh, see, they're so yeah, it's just washingtonpost dot com slash news dash site matt dash index dot xml Um, just for the record, it's a site map that contains links toe all the categorize site maps like politics and opinions and then, like, tech and local and sports.

  • All that stuff.

  • Um, so yeah, definitely not.

  • No shadows specifically to the Washington Post.

  • Actually, don't really read Washington Post.

  • I just like it because it's got a slight map that leads to yet another site map, and it poses an interesting task for us.

  • There quite a few websites, but this is just one that I'm gonna use here.

  • So anyways, um, and also just in case, especially for the future tutorials, um, this might change, like like historically, when I've done tutorials using any other website not just for parsing, but for anything like a P I or anything.

  • They've always changed where these almost always changed.

  • So just be prepared that this might not be the same as when I'm covering it now.

  • So anyways, um, we do it.

  • Get request.

  • Basically, that just means Hey, we want to get some data from you as opposed to, like, a post request.

  • Hey, we're sending you some data, um, anyway, and that's gonna end up giving us basically the response, But But within that response, there's going to be the body.

  • So we're gonna say the bites.

  • And then also we don't care about the next thing.

  • We just need to unpack it.

  • Colin Eagles, I owe you til dot Read all and we're gonna read all from the response dot body from there.

  • We need to That's gonna be in bites.

  • As the name suggests, we need to convert it to a string.

  • So we're gonna say string wonders for body colon equals strength bites, and then we're gonna do response dot body dot capital C clothes.

  • Eso we free up those.

  • The resource is basically for that.

  • Made this made the request.

  • So, uh, with that, let's go ahead and Ah, run it.

  • I think I'm still running my Web servers.

  • I'll break that and rewrote.

  • Let's see if we got air imported, Not you.

  • Oh, we important format.

  • But then we wound up not using it.

  • Eventually, we are going to use it, but yeah, that's kind of annoying.

  • Like I know I'm going to use it.

  • I just I'm up to this point.

  • My code.

  • I want to make sure it runs, and then I'll use format.

  • But don't force me to do this.

  • Street body declared and not you.

  • Okay?

  • Yeah.

  • All right.

  • Um Oh, and here's why.

  • I wanted to use format so fine, whatever form of that print line, street body, and then lets go ahead and import format now.

  • All right, that was really enjoyable.

  • Let's run that one more time.

  • Hopefully, that's the end of our errors, all right?

  • And at the output, at least in my case, is that the site map?

  • So that's kind of what we expected.

  • So, uh, from here, either you would parse things like you could parse html and a some point we might talk about parsing html in ghost specifically, but this is XML.

  • So we're actually gonna talk about parsing the XML specifically and then eventually get to the point where we can part, you know, just the your l's.

  • And then we can go visit those your l's, which are themselves.

  • Site map scraps, amore information that way weaken aggregate news by term or whatever.

  • So, uh, that's it for this tutorial?

  • Pretty basic, but, um but yeah, that's how you're gonna grab, like the source code of some information off the Internet.

  • So if you have any questions, comments, concerns, whatever differently, even blow.

  • Otherwise I will see you in the next tutorial.

What's going on?

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

インターネットへのアクセス - Go Lang実践プログラミングチュートリアル p.10 (Accessing the internet - Go Lang Practical Programming Tutorial p.10)

  • 6 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語