package require http;
package require tls;
http::register https 443 ::tls::socket;
# get the HTML page respecting the redirections
set ncode 0;
while {$ncode == 0 || ($ncode >= 300 && $ncode < 400)} {
if {[catch {set t [http::geturl $url];} reason options] == 1} {
return -options $options $reason;
}
set ncode [http::ncode $t];
set meta [http::meta $t];
if {$ncode >= 300 && $ncode < 400} {
set url [dict get $meta location];
http::cleanup $t;
}
}
set encoding [lindex [split [split [dict get $meta content-type] ";"] "="] end]
set data [http::data $t];
http::cleanup $t;
# check for a multi-photo or animated-gif HTML page
set multiPhotoNodes [regexp -inline -all {<\w+\s+(?:\w+="[^\"]*"\s+)*class="(?:(?:\w+(?:\s|-))*)(?:multi-photo\s+photo-\d+)(?:(?:(?:\s|-)\w+)*)"(?:[^>]+)>\s*]+)>} $data];
if {[llength $multiPhotoNodes]} {
foreach {whole imgUrl} $multiPhotoNodes {
# do something with the image URL
}
} else {
set animatedGifodes [regexp -inline -all {(?:]*>\s+