Skip to content

02 Getting Started

Javid Sh edited this page Oct 14, 2021 · 22 revisions

Building a Grabber

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.

Example

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.

Grabbing Resources

Now you should provide the grabber with a URL to scrape. Then you can access the collection of all grabbed resources from grabResult.Resources.

Example

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.

Selecting Resources

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.

Example

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);
Clone this wiki locally