mIRC Homepage
Posted By: Ninko Newbie help please - 23/02/08 12:31 PM
Hi there,
I'm new to mIRC scripting and I'm really not understanding how to even attempt to do this. What I would like to do is get some info from a site, and to do that I have to use sockets? But I really don't understand them at all, if someone could write some basic code in order to do this I might get it, I find I learn better from seeing examples lol.

Something like, get the first line from a webpage and display it in a channel would be a good start for me to see lol.

Thanks


Ninko
Posted By: The_JD Re: Newbie help please - 23/02/08 05:38 PM
have a search, there are plenty of basic examples.
Posted By: Ninko Re: Newbie help please - 23/02/08 08:07 PM
I did, but I didn't really come up with much.


Ninko
Posted By: sparta Re: Newbie help please - 23/02/08 08:22 PM
try look for socket .. or sockets
Posted By: Riamus2 Re: Newbie help please - 23/02/08 11:26 PM
Here's a very basic example.

Code:
alias opensocket {
  sockopen socketname www.host.com 80
}

on *:sockopen:socketname: {
  sockwrite -n $sockname GET /path/filename.html HTTP/1.0
  sockwrite -n $sockname Host: www.host.com $+ $crlf $+ $crlf
}

on *:sockread:socketname: {
    if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %temptext
    sockread %temptext
    if (sometext isin %temptext) { echo -a %temptext }
    elseif (some*text* iswm %temptext) { set %var $gettok(%temptext,1,32) }
  }
}


You'll need to replace the "socketname" (unless you want it called that) in all 3 location. You also have to replace both website hosts and the path\filename.html. You may also want to change the alias name to suit your needs. Finally, you can adjust the IF/ELSEIF section to suit your needs. I just gave a couple examples of what can go there. Normally, you're not looking to output everything on a page, so you need to parse it using IF checks and then you either output it or put it into variables to be used later in some way.

There are other things that can be used in the SOCKOPEN event and may even be necessary depending on the site you're using. In general, this should do what you need.

If you just want an output of the HTML source to make sure you're getting what you should be getting, you can remove the IF/ELSEIF lines and instead insert echo @SocketTest %temptext instead. (Make sure you create that window before trying the socket by using /window -n @SocketTest ).

To test afterwards, just call the alias.
Posted By: Ninko Re: Newbie help please - 24/02/08 03:22 PM
Thanks for that example Riamus2.
Is it possible to get XML pages, as when I try using that example, it gives...

HTTP/1.1 200 OK

Thats it.

Thanks


Ninko
Posted By: Trashlord_ Re: Newbie help please - 24/02/08 05:10 PM
If you're new to mIRC scripting, I would really recommend you to lay off sockets for a while, until you learn mIRC more in depth.
Posted By: Ninko Re: Newbie help please - 24/02/08 05:36 PM
Oh I understand that, but all I'm trying to do is get whats in a xml file and save it to a txt file on my computer.

I managed to more or less get it working, but it doesn't seem to be getting everything in the file.

Any help please


Ninko
Posted By: Miguel_A Re: Newbie help please - 24/02/08 09:32 PM
Hi.

Using the Riamus2 example you can do it with binary variables.

Code:
alias opensocket {
  sockopen socketname www.host.com 80
}

on *:sockopen:socketname: {
  sockwrite -n $sockname GET / HTTP/1.0
  sockwrite -n $sockname Host: www.host.com $+ $crlf $+ $crlf
}

on *:sockread:socketname: {
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    ;This will read the incoming data and set into the binary variable &Data
    sockread &data
    ;This will write in the file named Test.txt the incoming information
    bwrite Test.txt -1 &data
  }
}


good luck
© mIRC Discussion Forums