It should give you a basic idea of how to pull the page, parsing the information is up to you.if {[catch {set wzsock [socket -async www.wunderground.com 80]} sockerr]} {
puthelp "NOTICE $nick :$sockerr"
puthelp "NOTICE $nick :Try again later, look out the window till then!"
close $wzsock
return 0
}
puts $wzsock "GET $webpage"
flush $wzsock
DragnLord wrote:if all else fails, you can check out StrikeLight's egghttp.tcl script and tutorial that can be found on www.tclscript.com
you can get the script from here
tutorial
I think the best way is to do as DragnLord first suggested and use other scripts to help you get what you basically needLongbow wrote:I've tried using the egghttp.tcl tutorial, but it never works.
Thats what I said I used, but always get errors.DragnLord wrote:if all else fails, you can check out StrikeLight's egghttp.tcl script and tutorial that can be found on www.tclscript.com
you can get the script from here
tutorial
Tcl error [pub:on]: invalid command name "egghttp:geturl"
Code: Select all
set sock [egghttp:geturl $url your_callbackproc]
Code: Select all
# egghttp_example.tcl
# Config
set url "http://www.mysite.com/page.php?get=online"
# End of config
if {![info exists egghttp(version)]} {
putlog "egghttp.tcl was NOT successfully loaded."
putlog "egghttp_example.tcl has not been loaded as a result."
} else {
proc your_callbackproc {sock} {
global url
set headers [egghttp:headers $sock]
set body [egghttp:data $sock]
regsub -all "\n" $body "" body
regsub -all -nocase {<br>} $body "<br>\n" body
regexp {(.*?) Total, (.*?) guests, (.*?) members, (.*?) anonymous members} $body - online
putserv "NOTICE $nick :$online"
}
bind pub - !online pub:on
proc pub:on {nick uhost hand chan text} {
global url
set sock [egghttp:geturl $url your_callbackproc]
return 1
}
putlog "egghttp_example.tcl has been successfully loaded."
}
Code: Select all
70 Total, 11 guests, 59 members, 0 anonymous members
I've never had much luck using more then one (.*?) per regexp.[/quote]proc your_callbackproc {sock} {
global url
set headers [egghttp:headers $sock]
set body [egghttp:data $sock]
regsub -all "\n" $body "" body
regsub -all -nocase {<br>} $body "<br>\n" body
regexp {(.*?) Total} $body match ptotal
regexp {(.*?) guests} $body match pguests
regexp {(.*?) members} $body match pmemb
regexp {(.*?) anonymous} $body match panon
puthelp "NOTICE $nick :$ptotal Total, $pguests Guests, $pmemb Members, $panon Anonymous users online"
}
The script will then show the variable $ptotal in telnet/dcc chat.regexp {(.*?) Total} $body match ptotal
putlog "total members = $ptotal"
Mm... true. Since it was originally a DCC command, i'll look into that.stdragon wrote:Well, one thing that jumps out at me is that in your callback, $nick is undefined.
Also, who knows if your regexp is actually working. There are many ways the html could be formatted to show the text you've given. If you gave the actual url it might help.
Code: Select all
putlog "test"
Code: Select all
putlog "$ptotal Total, $pguests Guests, $pmemb Members, $panon Anonymous users online"
putlog "body = $body"
regexp {(.*?) Total} $body match ptotal