-
Notifications
You must be signed in to change notification settings - Fork 45
02 Getting Started
First things first. To start grabbing stuff, the first thing you'll need is to build a grabber - the sole purpose of GrabberBuilder
.
It provides a fluent way to build a multi-grabber.
var grabber = GrabberBuilder.New()
.UseDefaultServices()
.AddYouTube()
.AddInstagram()
.AddVimeo()
.AddHls()
.AddPornHub()
.Build();
Note: You need to install corresponding grabber packages to be able to add them to the grabber builder e.g. SharpGrabber.YouTube
.
Now you should provide the grabber with a URL to scrape.
Then you can access the collection of all grabbed resources from grabResult.Resources
.
var grabResult = await grabber.GrabAsync(new Uri("https://www.youtube.com/watch?v=LTseTg48568"));
Note: In the example above the simplest form of GrabAsync
is used. You can provide CancellationToken
, IProgress
, and GrabOptions
to other overloads. GrabOptions
allows you to avoid grabbing unnecessary information and therefore avoid useless process cycles and potential network usage.
The collection of grabbed resources returned by GrabAsync
usually contains various types of grabbed resources, such as images and video. Naturally, they need to be filtered in most situations. You may use the extension methods named Resource
and Resources
for convenience.
Console.WriteLine("Grabbed {0}", grabResult.Title);
var info = grabResult.Resource<GrabbedInfo>();
var images = grabResult.Resources<GrabbedImage>().ToArray();
var mediaFiles = grabResult.Resources<GrabbedMedia>().ToArray();
Console.WriteLine("Found {0} images and {1} media files", images.Length, mediaFiles.Length);