mIRC Home    About    Download    Register    News    Help

Print Thread
#14247 05/03/03 09:57 PM
Joined: Feb 2003
Posts: 32
S
SaX0n Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Feb 2003
Posts: 32
The Problem:

I am reading data from a website with the below code. And i Get this error message on some lines of data:

/.search.in: line too long (line 19, script.mrc)

This is very odd because as you can see the data is first put into a variable (%t), and this DOESNT cause the old "set line too long" error message.

The question is, how to avoid this?
Reading data by X number of bytes into a &binvar would be to slow. The webserver sends neat CRLF terminated lines, So i would have to re-construct those lines, and THEN parse out the HTML, And then Parse out the bits of data i really want. This would be too slow (Imagine it's for a script that searches google). I need a simple way of prevent that unusual 'line too long' error. As you can see, i tried silencing the call to the 'search.in' Alias, however, mIRC does not respect that with it's error messages..


The Code:

on *:SOCKREAD:search:{
if ($sockerr) return
var %t
sockread %t
if (!$sockbr) return
if (%t) .search.in %t
}

alias search.in {
if ($1-) echo -s $1-
}

#14248 06/03/03 03:06 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Although %var content may be too long for many commands such as /write, /echo and /set, it's still possible to handle it with identifiers like $right, $left, $mid, $pos, $wrap and - $regex.

It's possible to force wrapping by using a loop like -
Code:

var %i = 1
while $mid(%data,%i,400) {
  search.in $ifmatch
  inc %i 400
}

but in this way some of the urls may cut somewhere in the 400th (or 800th) char, and search.in will not be able to handle them.

I think $regex is a fair solution for this. Here's a sample script:
Code:

alias g sockopen g www.google.com 80 | sockmark g $1-
on *:sockopen:g:{
  sockwrite -tn g GET /search?as_q= $+ $sock(g).mark $+ &num=100 HTTP/1.1
  sockwrite -tn g Host: www.google.com
  sockwrite -tn g
}
on *:sockread:g:{
  var %s
  sockread %s

  if $regex(%s,/<p class=g><a href=(\S+)>/gi) {
    var %i = 1
    while $regml(%i) {
      echo -s $ifmatch
      inc %i
    }
  }
}

Try /g peace, for example, and check the status window.

As you can see, the $regex pattern is: /<p class=g><a href=(\S+)>/gi

The html parts is used for identifying url results, where \S+ matches the url itself and enclosed by quotes to tell mIRC we want to save them for later reference by $regml(N).

For more information check the Regex tutorial from mircscripts.org, and man.txt for further reference.

You can also get some ideas from other scripters who made google scripts.


Link Copied to Clipboard