| View previous topic :: View next topic |
| Author |
Message |
angelbroz Voice
Joined: 16 Dec 2007 Posts: 1
|
Posted: Sun Dec 16, 2007 5:32 pm Post subject: Regexp Problem.. SOS |
|
|
Hi there i'm making a script
I'd like to get somes values from a webpage
>Groundshaker</A> (exori mas) </TD><TD>Attack </TD><TD>Instant</TD><TD>33</TD>.......
i have something
| Code: |
proc spell {nick uhost hand chan text} {
#set text [string totitle $text]
set query "http://www.tibia.com/library/?subtopic=spells"
set http [::http::geturl $query]
set html [::http::data $http]
set k ">(.*?)</A> \($text\)</TD><TD>(.*?) </TD><TD>(.*?)</TD><TD>(.*?)</TD><TD>(.*?)</TD><TD>(.*?)</TD><TD>(.*?)</TD></TR>"
regexp $k $html - spell cat type lvl mana price prem
putserv "privmsg $chan :$spell / Formula: $text / Category: $cat / Type: $type / Lvl: $lvl / Mana: $mana / Price: $price / Premium: $prem"
}
|
but dont works
[14:44] <~angelbroz> !spell exori has
Tcl error [spell]: couldn't compile regular expression pattern: parentheses () not balanced
plx help |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Sun Dec 16, 2007 9:12 pm Post subject: |
|
|
A little "light" reading is in order: regexp _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Sun Dec 16, 2007 10:58 pm Post subject: |
|
|
| Code: |
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.. |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Sun Dec 16, 2007 11:06 pm Post subject: |
|
|
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.. |
|
| Back to top |
|
 |
|