Posted to tcl by wIreS at Tue Jul 24 11:57:18 GMT 2007view raw

  1. #!/bin/sh
  2. exec tclsh8.4 "$0" ${1+"$@"}
  3. package require tdom
  4. package require http
  5. set url "http://localhost"
  6. set page [::http::data [::http::geturl $url]]
  7. set doc [dom parse -html $page]
  8. set root [$doc documentElement]
  9. set node [$root selectNodes {//html[1]/body[1]/div[3]/p[1]/span[3]}]
  10. set text [[[lindex $node 0] childNodes] nodeValue]
  11. puts "[string trim $text]"

Comments

Posted by wIrEs at Tue Jul 24 12:06:25 GMT 2007 [text] [code]

invalid command name "" while executing "[lindex $node 0] childNodes" invoked from within "[[lindex $node 0] childNodes] nodeValue" invoked from within "set text [[[lindex $node 0] childNodes] nodeValue]" (file "./http" line 11)

Posted by mjanssen at Tue Jul 24 13:07:56 GMT 2007 [text] [code]

#!/bin/sh exec tclsh8.4 "$0" ${1+"$@"} package require tdom package require http set url "http://localhost" set page [::http::data [::http::geturl $url]] set doc [dom parse -html <myroot>$page</myroot>] set root [$doc documentElement] set nodes [$root selectNodes {//div[@id="keys"]/p/span}] foreach node $nodes {puts [$node asText]}