Python for the .NET developer Transcripts
Chapter: Package management and external libraries
Lecture: C# package app

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Well things are about to get really fun
0:01 and exciting, we're going to write a program
0:04 that uses a bunch of cool libraries
0:06 and first we're going to check out
0:07 the equivalent in C#.
0:10 So over here I've created this thing called
0:12 Ch5_nuget and it's an
0:14 application that does web scraping.
0:16 You can see it proclaims it with its title right there.
0:20 The idea is that we're going to go visit Talk Python
0:23 my podcast here, and there's a little shortcut URL
0:26 if you just go, like, 212 or just, you know
0:28 that slash a number, it will automatically find its way
0:31 over to the actual thing that it's looking for.
0:34 So what we're going to do is we're going to write
0:36 a program that's going to go and go right now
0:40 it's going to go for the ten episodes
0:42 220 to 230, and its going to go
0:44 actually download all of the HTMl
0:48 and it's going to get that HTML and it's going to parse it
0:50 and try to pull out the title that's in the H1 tag
0:53 and then it's going to say that it found it.
0:55 Let's just first run it and see what it does.
0:58 Alright so it's running, look, it's getting it.
1:00 Found the title, 'Machine Learning in the Cloud.'
1:02 Empowering developers with this, and so on, right.
1:05 'Twelve Lessons from a Hundred Days of Web.'
1:08 And off it goes. And, now it's done.
1:11 It went and downloaded all that stuff off the website
1:14 it parsed the HTML, and so on.
1:16 Now, this whole program is 76 lines of code.
1:20 Do you think we're able to do that in 76 lines?
1:23 No, that's super complicated stuff
1:25 but the cool thing is, we didn't have to worry about it.
1:28 This is something that we're able to just
1:30 reference off of NuGet.
1:31 So let's go look at the packages that
1:33 we're working with here. Manage NuGet packages.
1:37 Go to installed, and the one that we have installed
1:40 here is HtmlAgilityPack
1:42 and because we're doing .NET Core
1:44 it's the .NET Core version of that.
1:46 So the idea is, we're going to go over here
1:49 and we're going to download this, and then this and then
1:50 this get HTML, I don't know, get title from HTML
1:55 it's just this. Maybe you caught it before.
1:56 And we go go in and we create an HTML document
2:00 we load up the stuff we got from the website
2:03 and we just select the single node, H1
2:05 and get the innertext and trim it.
2:07 And as you saw, it works like a champ.
2:10 Alright, those are the titles of those episodes, like
2:13 those are the H1 tags if you went in and found it.
2:15 We're also happen to be using HDP client
2:20 so we use some from there, but also we've got .NET Core
2:24 itself coming down that way as well from NuGet I believe
2:28 so we were able to go out and find this library and
2:30 add it, and we could even do things like
2:33 see if there's any updates.
2:35 I don't know, are there? It doesn't look like it.
2:37 But if there were, it would tell us, right?
2:39 So if there were updates for these packages we could
2:41 push a button and it would change it and get new ones.
2:44 This is a pretty cool little program that goes
2:46 and does that, downloads it, pulls up the title and just
2:48 prints it out. It's actually doing a
2:50 ton of work for how little code we had to write.