| View previous topic :: View next topic |
| Author |
Message |
NewzUK Master
Joined: 18 Nov 2002 Posts: 200 Location: Auckland, New Zealand
|
Posted: Thu Jan 11, 2007 11:17 am Post subject: web query |
|
|
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 |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Thu Jan 11, 2007 12:03 pm Post subject: |
|
|
| 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 |
|
 |
NewzUK Master
Joined: 18 Nov 2002 Posts: 200 Location: Auckland, New Zealand
|
Posted: Thu Jan 11, 2007 12:49 pm Post subject: |
|
|
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 |
|
 |
r0t3n Owner
Joined: 31 May 2005 Posts: 507 Location: UK
|
Posted: Thu Jan 11, 2007 1:03 pm Post subject: |
|
|
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 |
|
 |
|