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 

web query

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


Joined: 18 Nov 2002
Posts: 200
Location: Auckland, New Zealand

PostPosted: Thu Jan 11, 2007 11:17 am    Post subject: web query Reply with quote

Hi - I`m trying to retrieve the first line of a list of headlines from a webpage, but instead it gets the last one at the bottom of the list...?

Here`s the first part of the script - 2007- is what I`m using to identify the lines...

set query "http://a-website-goes-here.com"
set token [http::geturl $query]
set all [http::data $token]
foreach line [split $all \n] {
if {[string match "*2007-*" $line]} {

Thanks in advance for any help
_________________
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
rosc2112
Revered One


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

PostPosted: Thu Jan 11, 2007 12:03 pm    Post subject: Reply with quote

It gets the last line because of the foreach, each time it matches, it clobbers the 1st match.. So, you should take out the foreach, or alternatively use lappend to append each subsequent match and then use lindex 0 to get the 1st match.
Back to top
View user's profile Send private message
NewzUK
Master


Joined: 18 Nov 2002
Posts: 200
Location: Auckland, New Zealand

PostPosted: Thu Jan 11, 2007 12:49 pm    Post subject: Reply with quote

great thanks for the help ros...it`s working fine now.

thanks again!
_________________
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Thu Jan 11, 2007 1:03 pm    Post subject: Reply with quote

or you could use break, instead of appending each result?

Code:
set match ""
foreach line [split $all \n] {
  if {[string match *2007-* $line]} {
    set match "$line"
    break
  }
}
if {$match == ""} { return }
# continue with script

_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
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