mIRC Home    About    Download    Register    News    Help

Print Thread
#195382 23/02/08 12:31 PM
Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
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

Last edited by Ninko; 23/02/08 12:46 PM.
Joined: Mar 2006
Posts: 395
T
Pan-dimensional mouse
Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
have a search, there are plenty of basic examples.


[02:16] * Titanic has quit IRC (Excess Flood)
Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
I did, but I didn't really come up with much.


Ninko

Joined: Feb 2003
Posts: 3,432
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
try look for socket .. or sockets


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.


Invision Support
#Invision on irc.irchighway.net
Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
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

Joined: Oct 2007
Posts: 51
T
Babel fish
Offline
Babel fish
T
Joined: Oct 2007
Posts: 51
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.

Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
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

Joined: Aug 2003
Posts: 144
M
Vogon poet
Offline
Vogon poet
M
Joined: Aug 2003
Posts: 144
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

Last edited by Miguel_A; 24/02/08 09:33 PM.

Link Copied to Clipboard