|
-
May 31st, 2011, 10:46 AM
#1
Thread Starter
Frenzied Member
[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();
-
May 31st, 2011, 11:02 AM
#2
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
-
May 31st, 2011, 11:25 AM
#3
Thread Starter
Frenzied Member
Re: Anyother way to save images off the web?
Last edited by FishGuy; Jun 1st, 2011 at 03:14 AM.
-
Jun 1st, 2011, 01:56 AM
#4
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
-
Jun 1st, 2011, 03:13 AM
#5
Thread Starter
Frenzied Member
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.
-
Jun 1st, 2011, 05:37 AM
#6
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. 
-
Jun 1st, 2011, 06:03 AM
#7
Thread Starter
Frenzied Member
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.
-
Jun 1st, 2011, 07:38 AM
#8
Thread Starter
Frenzied Member
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.
-
Jun 2nd, 2011, 01:27 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|