egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Regexp Problem.. SOS

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
angelbroz
Voice


Joined: 16 Dec 2007
Posts: 1

PostPosted: Sun Dec 16, 2007 5:32 pm    Post subject: Regexp Problem.. SOS Reply with quote

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 Sad

[14:44] <~angelbroz> !spell exori has

Tcl error [spell]: couldn't compile regular expression pattern: parentheses () not balanced

plx help
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Sun Dec 16, 2007 9:12 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sun Dec 16, 2007 10:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sun Dec 16, 2007 11:06 pm    Post subject: Reply with quote

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! Smile

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber