Get All Images From External URL / Website

İbrahim Sezen

This code is working nice... I dont have problem.

var urls = from lnks in document.DocumentNode.Descendants()
  where (lnks.Name == "a" && lnks.Attributes["href"] != null &&
        (lnks.Attributes["href"].Value.ToString().Contains("jpg")
         || lnks.Attributes["href"].Value.ToString().Contains("png")
         || lnks.Attributes["href"].Value.ToString().Contains("bmp")
         || lnks.Attributes["href"].Value.ToString().Contains("jpeg")
         || lnks.Attributes["href"].Value.ToString().Contains("gif"))
        )
        select new
        {
         Url = lnks.Attributes["href"].Value
        };

But This one always return null:

var urls = from lnks in document.DocumentNode.Descendants()
           where (lnks.Name == "a" || lnks.Name == "img") && 
                 (lnks.Attributes["href"] != null || lnks.Attributes["src"] != null) &&
                 (
                 lnks.Attributes["href"].Value.ToString().Contains("jpg")
                 || lnks.Attributes["href"].Value.ToString().Contains("png")
                 || lnks.Attributes["href"].Value.ToString().Contains("bmp")
                 || lnks.Attributes["href"].Value.ToString().Contains("jpeg")
                 || lnks.Attributes["href"].Value.ToString().Contains("gif")
                 || lnks.Attributes["src"].Value.ToString().Contains("jpg")
                 || lnks.Attributes["src"].Value.ToString().Contains("png")
                 || lnks.Attributes["src"].Value.ToString().Contains("bmp")
                 || lnks.Attributes["src"].Value.ToString().Contains("jpeg")
                 || lnks.Attributes["src"].Value.ToString().Contains("gif")
                 )
           select new
           {
            Url = lnks.Attributes["src"] != null ? lnks.Attributes["src"].Value : lnks.Attributes["href"].Value
           };

What's my mistake ? and is this a correct way to take images ?

jwillmer

This is the code for image nodes. Make a function out of it and you can use it for any node:

GetLinksFromDocument(document, nodeName, linkAttributeName)

using HtmlAgilityPack;

var urls = new List<string>();
var prefixList = new[] { "jpg", "jpeg", "png", "bmp", "gif" };
var document = new HtmlWeb().Load("http://jwillmer.de");

var imageNodes = document.DocumentNode.Descendants("img");  
var imageLinks = imageNodes.Where(node => node.Attributes.Contains("src"))
                           .Select(node => node.Attributes["src"].Value);

urls.AddRange(imageLinks.Where(link => prefixList.Any(link.EndsWith)));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get all images from website

From Dev

Get urls of images from external url

From Dev

Extracting Images from the external website

From Dev

Downloading all images from website

From Dev

Download millions of images from external website

From Dev

Download millions of images from external website

From Dev

Get images from other website

From Dev

How to get all images from a url to picturebox in c#?

From Dev

How to download all images from a website?

From Dev

How to download all images from a website?

From Dev

How to fetch image from Website url and store all images in folder in PC?

From Dev

Get DIV content from external Website

From Dev

Get meta description from external website

From Dev

How to get an href from an external website?

From Dev

Get DIV content from external Website

From Dev

Get meta description from external website

From Dev

Get list of plugins from external Wordpress website

From Dev

Nodejs - Get content from external website

From Dev

How to get all files like: js,css,images from a website to save it for offline use?

From Dev

How get all url images in a page with JSoup?

From Dev

JQuery to expand all collapsible sections of a page (from external website)

From Dev

In php how can I download images from external website and save into my website?

From Dev

Copy all images from remote url in PHP

From Dev

open all website URL within App and external URLs using external browser in WebView?

From Dev

Get all urls from a website using python

From Dev

Get all urls indexed to google from a website

From Dev

Get Json Object from external URL with PHP

From Dev

Get Json Object from external URL with PHP

From Dev

Import WordPress post images as featured image from external URL

Related Related

  1. 1

    Get all images from website

  2. 2

    Get urls of images from external url

  3. 3

    Extracting Images from the external website

  4. 4

    Downloading all images from website

  5. 5

    Download millions of images from external website

  6. 6

    Download millions of images from external website

  7. 7

    Get images from other website

  8. 8

    How to get all images from a url to picturebox in c#?

  9. 9

    How to download all images from a website?

  10. 10

    How to download all images from a website?

  11. 11

    How to fetch image from Website url and store all images in folder in PC?

  12. 12

    Get DIV content from external Website

  13. 13

    Get meta description from external website

  14. 14

    How to get an href from an external website?

  15. 15

    Get DIV content from external Website

  16. 16

    Get meta description from external website

  17. 17

    Get list of plugins from external Wordpress website

  18. 18

    Nodejs - Get content from external website

  19. 19

    How to get all files like: js,css,images from a website to save it for offline use?

  20. 20

    How get all url images in a page with JSoup?

  21. 21

    JQuery to expand all collapsible sections of a page (from external website)

  22. 22

    In php how can I download images from external website and save into my website?

  23. 23

    Copy all images from remote url in PHP

  24. 24

    open all website URL within App and external URLs using external browser in WebView?

  25. 25

    Get all urls from a website using python

  26. 26

    Get all urls indexed to google from a website

  27. 27

    Get Json Object from external URL with PHP

  28. 28

    Get Json Object from external URL with PHP

  29. 29

    Import WordPress post images as featured image from external URL

HotTag

Archive