Download from web

P

Peter Eriksson

I have made an application that downloads images from a website with
code like this:

Dim Client As WebClient = New WebClient()
imageUrl = http://www.websíte.com/image.jpg
Client.DownloadFile(imageUrl, dest)

This works fine but the website returns a defaultimage if the image is
adressed with a complete url. You have to first wisit the mainpage and
then you can adress the image.
How can I achive this?
 
C

Cor Ligthert [MVP]

Peter,

It is not impossible that the image is protected in a database.

Be aware that you are hacking when you try to get protected data from a
webserver.
At least in my country is there a penalty for that.

Cor
 
P

Peter Eriksson

No, I don't think it is hacking.
It is a public page. You can easily download
the pictures with rightclick in the browser.
It was just a testproject to learn about the WebClient class.
 
G

gene kelley

I have made an application that downloads images from a website with
code like this:

Dim Client As WebClient = New WebClient()
imageUrl = http://www.websíte.com/image.jpg
Client.DownloadFile(imageUrl, dest)

This works fine but the website returns a defaultimage if the image is
adressed with a complete url. You have to first wisit the mainpage and
then you can adress the image.
How can I achive this?
On the mainpage, right-click the image, properties, and see what the
actual URL is to the image. That URL should retrive the correct image
if the image is static, or, it's an image that is updated periodically
but has an static file name of something like .. /latest.jpg. If it's
an updating image and has an ultimate filename that is based on
something like date/time, you will have to predetermine the current
URL (i.e. a parseHTML routine of some sort)

If VB2005 and you just want to write to disk, you can also use this
with it's various arguments:
My.Computer.Network.DownloadFile(someURL, someDest)


Gene
 
G

gene kelley

No, I don't think it is hacking.
It is a public page. You can easily download
the pictures with rightclick in the browser.
It was just a testproject to learn about the WebClient class.


If simply downloading for personal use, via browser or app, there is
no problem. However, if in an application that ultimately downloads
and displays images form a website and the app is to be distributed,
it's best to check the website(s) to see if there is any copyright
restrictions or premissions required.

Gene
 
A

Andrew Morton

Peter said:
I have made an application that downloads images from a website with
code like this:

Dim Client As WebClient = New WebClient()
imageUrl = http://www.websíte.com/image.jpg
Client.DownloadFile(imageUrl, dest)

This works fine but the website returns a defaultimage if the image is
adressed with a complete url. You have to first wisit the mainpage and
then you can adress the image.
How can I achive this?

Might it be that the web site checks the referer (sic) property when serving
images in order to prevent what you're trying to do? (Although I don't know
if referer would be set by making a request through .NET.) If you try it on
a web server that you control, does it work as desired first time? You can
also look at the logs for clues.

Just because a URL ends in .jpg doesn't mean that it came directly from the
file - there could be a filter inbetween.

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top