如何使用TCL http包捕获html表

时间:2013-11-24 12:57:01

标签: http tcl

如何使用带有示例

的TCL http包捕获html表

我尝试了一个示例,但它很简单地从会话中退出。

package require http
package require base64
set auth "Basic [base64::encode XXXX:XXXXX]"
set headerl [list Authorization $auth]
set query "http://100.59.262.156/"
set tok [http::geturl $query -headers $headerl]
set res [http::data $tok]
http::status $tok

# After login  into the session, i am moving one page another web page

set  goquery [http::formatQuery "http://100.59.262.156/web/sysstatus.html"]

# After this i am log out from the session. I am unable to find reason.

set tok [http::geturl $query -query http://100.59.262.156/web/sysstatus.html]
set res [http::data $tok]

# After this i will get a table output i need capture this table
# how to capture tables using 

http::status $tok

由于

Malli

1 个答案:

答案 0 :(得分:0)

我在这里看到一些误解:

  • 您应该清除http::geturl返回的令牌。您可以使用http::cleanup $token执行此操作。否则会导致内存泄漏。
  • 必须为每个请求发送基本的auth标头。通常可以使用正确的标题请求所需的网站。
  • http::formatQuery用于POST或GET参数,不用于URL(您可以将其用于查询URL部分,但不能用于整个URL)。放弃。
  • http包不会为您解析HTML。你必须自己做。我建议使用tdom

因为我不知道你的网站返回什么,我不能告诉你如何解析它,但是这里有一个开始的脚本:

package require http
package require base64
package require tdom

set auth "Basic [base64::encode XXXX:XXXXX]"
set headerl [list Authorization $auth]
set url "http://100.59.262.156/web/sysstatus.html"

set tok [http::geturl $url -headers $headerl]
# TODO: Check the status here. If you get a 403, the login information was not correct.
set data [http::data $tok]
# Important: cleanup
http::cleanup $tok

# Now parse it
dom parse -html $data doc
# Search for the important stuff, walk over the dom... to the the important information