Results 1 to 9 of 9

Thread: [RESOLVED] Anyother way to save images off the web?

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [RESOLVED] Anyother way to save images off the web?

    I am trying to programatically save the images from a website, I have tried both the
    webClient.DownloadFile
    method and HttpWebRequest.Create as below but keep hitting - $exception {"The remote server returned an error: (407) Proxy Authentication Required."} System.Exception {System.Net.WebException}


    If I can right click and save the image whats the difference, is there any other way?
    Code:
     private String LocalizeImages(String htmlText)
          {
              String parsedtext = htmlText;
              HtmlDocument doc = new HtmlDocument();
              doc.LoadHtml(parsedtext);
              HtmlNodeCollection nc = doc.DocumentNode.SelectNodes("//img[@name]");
              if (nc != null)
              {
                  foreach (HtmlNode link in nc)
                  {
    
                      HtmlAttribute source = link.Attributes["src"];
    
                      String fullfilename = source.Value;
    
                      String filename = Path.GetFileName(fullfilename);
                      System.Net.WebClient webClient = new WebClient();
                      String target = Server.MapPath(@"\images\pdfImages\" + filename).ToString();
                      //webClient.DownloadFile(fullfilename, target);
    
                      System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(fullfilename);
                 System.Net.HttpWebResponse res  = (System.Net.HttpWebResponse)req.GetResponse();
               
           
    
                System.IO.Stream str = res.GetResponseStream();
                if (str != null)
                {
                    System.Drawing.Image img = System.Drawing.Image.FromStream(str);
                    img.Save(target, System.Drawing.Imaging.ImageFormat.Jpeg);
                }
                res.Close();

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Anyother way to save images off the web?

    the difference is that when you right-click save as on the image, you're saving what's in the cache... it doesn't re-get the image from the server.

    If I had to guess, I'd say that what ever site you're going against has proxy authen turned on to avoid hot linking to their images.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Anyother way to save images off the web?

    Posted in error, sorry.
    Last edited by FishGuy; Jun 1st, 2011 at 03:14 AM.

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Anyother way to save images off the web?

    I am confused.

    Your two posts in this thread seem to be talking about two completely separate issues, is that correct, or did I miss something?

    Gary

  5. #5

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Anyother way to save images off the web?

    Yes my apologies that last post was meant for the thread I had about client ID and Javascript.

    This issue should be solely about extracting images from web pages.

  6. #6
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Anyother way to save images off the web?

    are you sure "fullfilename" is a valid url to the image? Have you tried your code on an image/path that you know exists.
    The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded.

  7. #7

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Anyother way to save images off the web?

    Yes I am although I tried a different image, one one my own hosted web server which I know I havent applied an special restrictions to, System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
    the error occurs on the above line, I am now considering it is something at my employers end blocking the request either in or out, i.e. firewall rather than at the host.

    I tried this image
    http://www.cyprusstairlifts.com/imag...rliftsLogo.jpg

    I guess if someone else can obtain the same image outside of my network I would know that the problem is not with the host but internal.

  8. #8

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: [RESOLVED] Anyother way to save images off the web?

    Yup it was my workstation set up it all works fine on the webserver, which must be configured differently. Privided the folder to save the images in has granted the IIS user the correct rights.

  9. #9
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Anyother way to save images off the web?

    Just to confirm, I can hit that URL and see the image.

    Do you know what it is in your own set up that is preventing it?

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width