This is one portion of the [nstcl] package.
[[Describe the functions that nstcl provides for managing html]]
----
Here's a sample script demonstrating a use:
package require nstcl 1.0
namespace import nstcl::*
set url http://mini.net/tcl/
# the tag will be used to turn relative links into absolute links if
# tcllib is present, otherwise behavior is that of AOLserver's ns_hrefs command
set html ""
append html [ns_httpget $url]
# Keep track of lengths of URLs
set lengths([string length $html]) [list $url]
# Iterate through all the distinct links from the page fetched
foreach url [lsort -unique [ns_hrefs $html]] {
if {[catch { ns_httpget $url } html]} {
puts stderr "Couldn't fetch $url because: $html"
} else {
lappend lengths([string length $html]) $url
puts "Fetched $url"
}
}
# Sort and print in order of shortest to longest page length
foreach length [lsort -integer [array names lengths]] {
foreach url $lengths($length) {
puts "Length $length: $url"
}
}
----
[Category Command], a part of the [nstcl] package
| [Category Internet]