Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

TCL(Tool Command Language) Scripting

Grabbing a Web Page with Socket


New to tcl, but I wanted to try grabbing a web page with socket.  In
this case, it's Google's about page, and I'm trying to read it into a
variable called test.  Unfortunately, the script seems to never do
anything!  What am I doing wrong?

code
-------
set sockChan [socket "www.google.com" 80]
puts $sockChan "GET /intl/en/about.html HTTP/1.0\n\n"
gets $sockChan test
close $sockChan
-------

Also, is it important that www.google.com be in quotes?

Thanks!

- GeekUnit

On May 27, 4:31 pm, GeekUnit <mrn@gmail.com> wrote:

> New to tcl, but I wanted to try grabbing a web page with socket.  In
> this case, it's Google's about page, and I'm trying to read it into a
> variable called test.  Unfortunately, the script seems to never do
> anything!  What am I doing wrong?

> set sockChan [socket "www.google.com" 80]
> puts $sockChan "GET /intl/en/about.html HTTP/1.0\n\n"

You just need to flush the output. Some channels in Tcl are created by
default in block-buffered mode, sockets are in the group. Just insert
"flush $sockChan" after the [puts], (or change the buffering mode with
[fconfigure]), and your code will work.

That said, while putting your hands in the grease is an unbeatable way
of learning, for the specific task for http clientside in pure Tcl,
check out the already-written package http (it is in most distribs of
Tcl).

-Alex

You might take a look at http://wiki.tcl.tk/WebScraping and see if the
info there, and on the referenced pages, help.
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc