Avatar of rye004
rye004
Flag for United States of America asked on

In C# how do I get the full URL from HTMLImgClass?

I am writing a program to download images from a web page.  I am able to download the images, but I would also like to log the full path of where it came from.

Below is the code that I have written.

            WebBrowser scrapeWebBrowser = new WebBrowser();

            scrapeWebBrowser.Navigate("http://yahoo.com");

            HTMLDocument objHtmlDocument = (HTMLDocument)scrapeWebBrowser.Document;

            foreach (HTMLImgClass imageElement in objHtmlDocument.images)
            {
                //HTMLImage
                WebClient client = new WebClient();
                string fileName = System.IO.Path.GetFileName(imageElement.href);
                client.DownloadFileAsync(new Uri(imageElement.href), System.IO.Path.Combine(@"L:\temp\imagedownload\", fileName));

                //How do I get the full url for imageElement?
            }

Open in new window


Is it possible to return the full URL from my declared variable imageElement?
C#

Avatar of undefined
Last Comment
rye004

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
rye004

ASKER
Hi!  Yes, I did look at imageElement.href.  It only returned the name for the current image.  Thanks!
rye004

ASKER
I just tested again, and you are correct! Thank you again for your help! 😊
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck