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


Talk Python's Mastodon Michael Kennedy's Mastodon