Skip to content Skip to sidebar Skip to footer

Get And Download Pictures With AngleSharp

I started using Anglesharp for a Project, I need to get and download not only HTML but also images of the document. I know that in the Document object there is a property called Im

Solution 1:

You can use the LINQ API to get all attributes that contains image URL in a page, like so :

.....
var document = await BrowsingContext.New(config).OpenAsync(address);

//list all image file extension here :
var fileExtensions = new string[] { ".jpg", ".png" };

//find all attribute in any element...
//where the value ends with one of the listed file extension                     
var result = from element in document.All
             from attribute in element.Attributes
             where fileExtensions.Any(e => attribute.Value.EndsWith(e))
             select attribute;

foreach (var item in result)
{
    Console.WriteLine(item.Value);
}

Post a Comment for "Get And Download Pictures With AngleSharp"