| View previous topic :: View next topic |
| Author |
Message |
ryal Voice
Joined: 12 May 2005 Posts: 35
|
Posted: Thu Dec 15, 2005 1:17 pm Post subject: Help with egghelp.tcl |
|
|
Hi !
Im trying to parse the content of a webpage but it doesnt work (it does tho with some webpages but not with www.google.com).
Heres the code i use:
| Quote: |
proc parse_proc { nick uhost handle arg } {
global mychan sock
set d [date:offset [clock seconds] %m%d%y]
set url "http://www.google.com"
set target $nick
set sock [egghttp:geturl $url [list parseinfo $target $url] -timeout 600]
puthelp "PRIVMSG $target :$url"
}
proc parseinfo {target url sock} {
set headers [egghttp:headers $sock]
set body [egghttp:data $sock]
puthelp "PRIVMSG $target :hello"
puthelp "PRIVMSG $target :$headers"
puthelp "PRIVMSG $target :$body"
} |
It displays the right url, "hello" and then nothing. I know body is a big variable but it should display the first line (which it does for some websites, but not with google). Of course i loaded egghelp.tcl in my *.conf and it loads alright.
What did i do wrong? i do believe the error stands in the way i call egghttp:geturl but i dont know how to fix it |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Thu Dec 15, 2005 8:21 pm Post subject: |
|
|
3 things:
- try using a shorter timeout than 10min
- try using the header line "Connection: close"
- Try passing only the first line to puthelp via [string range $body 0 [string first $body "\n"]]. That saves your bot getting various errors from IRC Server and most likely getting spammed out (if it isnt trimmed to 510 bytes anyway)
Btw. headers also contain about 5-10 lines depending on HTTP server. _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Fri Dec 16, 2005 3:09 am Post subject: |
|
|
egghttp is outdated, do not use it
use Tcl's built-in http package instead _________________ connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code |
|
| Back to top |
|
 |
ryal Voice
Joined: 12 May 2005 Posts: 35
|
Posted: Fri Dec 16, 2005 6:08 am Post subject: |
|
|
Thx for the tip, didnt know there was a built in package.
Anyway, i still get the same error (that is http::data returns an empty string, no url data). Heres the new code:
| Code: |
proc parse_proc { nick uhost handle arg } {
global sock
set url "http://www.google.com"
set target $nick
set sock [::http::geturl $url -command [list parseinfo $target $url] -timeout 60]
puthelp "PRIVMSG $target :$url"
}
proc parseinfo {target url sock} {
set body [::http::data $sock]
::http::cleanup $sock
set body2 [string range $body 0 [string first $body "\n"]]
puthelp "PRIVMSG $target :hello"
puthelp "PRIVMSG $target :$body hello2"
}
|
It displays the url, "hello" and then "hello2" with nothing in front of it.
Any ideas?
PS: of course the timer wasnt 10' at first i just wanted to know if it could be a timer pb so i put an extra large.
Thanks for your help guys!
Last edited by ryal on Tue Dec 20, 2005 12:03 pm; edited 1 time in total |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Fri Dec 16, 2005 11:26 pm Post subject: |
|
|
try using it in the simpler, blocking form first - i.e. without -command switch
and use [code] tag when posting code, not [quote] _________________ connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code |
|
| Back to top |
|
 |
ryal Voice
Joined: 12 May 2005 Posts: 35
|
Posted: Tue Dec 20, 2005 12:02 pm Post subject: |
|
|
I get exactly the same result without the "-command".
Could this be a bug from the http package?
PS: sorry the for quote instead of code; i just fixed it |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Dec 20, 2005 11:21 pm Post subject: |
|
|
nope, it's bug in your script or/and your logic _________________ connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code |
|
| Back to top |
|
 |
|