Question on using urllib

O

Olivier Scalbert

Hello all,

Sorry if this question is not 100% python related, it is also related to
http or html ...

Everything takes place in this page:
http://www.infometeo.be/klanten/KYC/campage2mega.php

With the following program, I can download the 2 small meteo images,
without any problem:

import urllib

urllib.urlretrieve("http://www.infometeo.be/wwweather/currentimage.php?icao=EBFN",
"meteo1.jpg")
urllib.urlretrieve("http://www.meteokust.be/metstatgr.php?s=zb",
"meteo2.jpg")

But I would like to download the main background picture.

By looking inside the html page, it seems it's url is:
http://www.infometeo.be/img.php?iid=1057

....
<table bgcolor="#6699FF">
<tr>
<td>
<table width="1280" height="960"
background="http://www.infometeo.be/img.php?iid=1057">
<tr>
<td align="right" valign="bottom">
....

Warning, the iid may vary depending time ...

I try to download it with python:
urllib.urlretrieve("http://www.infometeo.be/img.php?iid=1057",
"picture.jpg")
But then I receive only 2 bytes: CR LF I think.

If I use this url with my browser (firefox), I also get nothing (a blank
page).
If I go back to the main page with the firebug plugin activated, I can
change the iid directly inside the html code with firebug, and then,
even previous pictures can be displayed ...

So I am a bit lost ... Any help would be very appreciate !!

Thanks,

Olivier
 
P

Peter Otten

Olivier said:
Sorry if this question is not 100% python related, it is also related to
http or html ...

Everything takes place in this page:
http://www.infometeo.be/klanten/KYC/campage2mega.php

With the following program, I can download the 2 small meteo images,
without any problem:

import urllib

urllib.urlretrieve("http://www.infometeo.be/wwweather/currentimage.php?icao=EBFN",
"meteo1.jpg")
urllib.urlretrieve("http://www.meteokust.be/metstatgr.php?s=zb",
"meteo2.jpg")

But I would like to download the main background picture.

By looking inside the html page, it seems it's url is:
http://www.infometeo.be/img.php?iid=1057
I try to download it with python:
urllib.urlretrieve("http://www.infometeo.be/img.php?iid=1057",
"picture.jpg")

The problem is indeed not Python-related. The provider of the images doesn't
like what you're trying to do and verifies the referer, i. e. that the page
you claim to be coming from is acceptable. Here's one way to satisfy that
check:

Now if you are using that workaround a lot he may come up with more
sophisticated techniques. So dont ;)

Peter
 
O

Olivier Scalbert

The problem is indeed not Python-related. The provider of the images doesn't
like what you're trying to do and verifies the referer, i. e. that the page
you claim to be coming from is acceptable. Here's one way to satisfy that
check:


Now if you are using that workaround a lot he may come up with more
sophisticated techniques. So dont ;)

Peter

Thanks Peter, it works perfectly !
At 60 fps I can even make a video ...
;-)

Olivier
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top