set timeout "60000"
set text [split [string tolower $text]]
set query "http://www.tibia.com/library/?subtopic=spells"
# Check if we even get the webpage?
catch {set page [::http::geturl $query -timeout $timeout]} error
if {[string match -nocase "*couldn't open socket*" $error]} {
puthelp "PRIVMSG $chan :Error: couldn't connect..Try again later."
return
}
if { [::http::status $page] == "timeout" } {
puthelp "PRIVMSG $chan :Error: Connection to timed out..Try again later."
return
}
set html [::http::data $page]
# regexp won't expand $vars, so do it here first:
set regex "HREF=\"http://www.tibia.com/library/?subtopic=spells&spell=.*?\">(.*?)</A> \($text\)</TD><TD>(.*?)</TD><TD>(.*?)</TD><TD>(.*?)</TD><TD>(.*?)</TD><TD>(.*?)</TD><TD>(.*?)</TD></TR><TR BGCOLOR=.*?<TD>"
if {[regexp $regex $html match spell cat type lvl mana price prem]} {
puthelp "PRIVMSG $chan :$spell / Formula: $text / Category: $cat / Type: $type / Lvl: $lvl / Mana: $mana / Price: $price / Premium: $prem"
} else {
puthelp "PRIVMSG $chan :Can't get data..."
}
Thats the jist of it. Do more error checking, use a var to expand input vars for regexp, and use PRIVMSG (uppercase) as I do believe it's case sensitive (might be wrong on that, I've always used uppercase.).
The locations of my subexpressions (.*?) might not be completely what you wanted, I just grabbed everything with regexp, edit to suit..
Actually, since it doesn't look like that webpage is gonna change much at all, why not just grab a copy and store it all in an array after reading it from disk (after cleaning up and saving it to disk), then you don't have to wait for it to grab the webpage everytime there's a query.. Arrays can be fun!
My earth calendar script does that, so does the tvrage script. They pull in fresh data once in a while just in case there's been changes..