Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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*<img\s+(?:\w+="[^\"]*"\s+)*src="([^\"]+)"([^>]+)>} $data];
- if {[llength $multiPhotoNodes]} {
- foreach {whole imgUrl} $multiPhotoNodes {
- # do something with the image URL
- }
- } else {
- set animatedGifodes [regexp -inline -all {(?:<img\s+(?:(?:\w+="[^\"]*"\s+)*)src="([^\"]+)"\s+(?:\w+="[^\"]*"\s)*class="\w*(?:\s|-)?animated-gif(?:\s|-)?\w*")|(?:<video\s+(?:\w+="[^\"]*"\s)*class="\w*(?:\s|-)?animated-gif(?:\s|-)?\w*"\s*[^>]*>\s+<source\s+(?:(?:\w+="[^\"]*"\s+)*)video-src="([^\"]+)")} $data];
- if {[llength $animatiedGifNodes] == 4} {
- foreach {whole url} $animatedGifodes {
- if {[string match {<img*} $whole]} {
- # process the thumbnail image URL
- } else {
- # process the animated GIF video URL
- }
- }
- }
- } else {
- # ...
- }
Advertisement
Add Comment
Please, Sign In to add comment