mIRC Home    About    Download    Register    News    Help

Print Thread
sockets; table rows #144986 17/03/06 12:59 AM
Joined: Jun 2005
Posts: 127
H
HAMM3R Offline OP
Vogon poet
OP Offline
Vogon poet
H
Joined: Jun 2005
Posts: 127
I have a socket to read info from a table. I'd like to save every row to a %var. So %var would be: row1, ro2, row3. I have a working socket that can get only the first row. How can i make it continute to grab the rest of the table?
Code:
on *:sockread:blah:{
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %data
    sockread %data
    if (<tr><td>*</td><td>*</td><td>*</td><td>*</td><td>*</td></tr> iswm %data) { 
      echo -a $nohtml(%data)
      sockclose $sockname
      halt
    }
  }
}


Thanks


-- HAMM3R (aka: alhammer)
http://www.HAMM3R.net
Re: sockets; table rows #144987 17/03/06 04:42 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
In your sockopen section put something like
Code:
 set %row 1 

The halt commands are unnecessary. The changes I made will store the non-html format of the line read into the variable(s). Also please note that the wildcard string that you're doing the comparison on might be matched on the very first match, so that would close the socket, even if there are more lines in the document.


Then change your sockread to
Code:
 on *:sockread:blah:{
  if ($sockerr) {
    echo -a Error.
  }
  else {
    var %data
    sockread %data
       set $+(%,row,%row) $nohtml(%data)
       inc %row
    if (<tr><td>*</td><td>*</td><td>*</td><td>*</td><td>*</td></tr> iswm %data) {
       echo -a $nohtml(%data)
       sockclose $sockname
    }
  }
}
 

Last edited by RusselB; 17/03/06 04:44 AM.
Re: sockets; table rows #144988 19/03/06 05:07 PM
Joined: Jun 2005
Posts: 127
H
HAMM3R Offline OP
Vogon poet
OP Offline
Vogon poet
H
Joined: Jun 2005
Posts: 127
Hmm. What I meant is I needed it to save the rows of the TABLE. Not the html code itself. So it needs to save it only if it matches the wildcard matchtext (signifying its part of the table). And I needed it in 1 variable, with commas seperating each row of the table. I can do that part of it. I just need it to go on to the next line of code after the match text, to see if the next line also matches. This way I can catch all of the rows in the table.

Re: sockets; table rows #144989 19/03/06 05:31 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Are you sure that every line of the table has that exact format? I think it might be easier to look for <table* at the beginning and </table* at the end.

Code:
on *SOCKREAD:*:{
  var %s
  sockread %s
  tokenize 32 %s

  if (&lt;table* iswm $1-) set %intable 1
  if (%intable) {
    ;Do something with table data here
    echo -s &gt; $nohtml($1-)
  }
  if (&lt;/table* iswm $1-) unset %intable
}


(untested code)

-genius_at_work

Re: sockets; table rows #144990 19/03/06 06:05 PM
Joined: Jun 2005
Posts: 127
H
HAMM3R Offline OP
Vogon poet
OP Offline
Vogon poet
H
Joined: Jun 2005
Posts: 127
Yes, every row in the table has the exact format of tags, just different data in place of the wildcard. The code you gave me ended up returning a few unwanted things that are scrambled in the middle of the <table> code. Could you write it using the table matchtext in my earlier post? Id appreciate it.


-- HAMM3R (aka: alhammer)
http://www.HAMM3R.net
Re: sockets; table rows #144991 19/03/06 06:34 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Try this code that I modified from RusselB's version.

[code]
on *:sockread:blah:{
if ($sockerr) {
echo -a Error.
return
}
var %data
sockread %data
if (<tr><td>*</td><td>*</td><td>*</td><td>*</td><td>*</td></tr> iswm %data) {
inc %row
set $+(%,row,%row) $nohtml(%data)
}
}

Each row is stored in variables like %row1 %row2 etc. One for each matching line of data that is sent on the socket.

-genius_at_work

Re: sockets; table rows #144992 19/03/06 07:43 PM
Joined: Jun 2005
Posts: 127
H
HAMM3R Offline OP
Vogon poet
OP Offline
Vogon poet
H
Joined: Jun 2005
Posts: 127
Great. I edited this and got it to set the %var right. But where do I put the command for when it's done setting the var? When its set the var with all the table rows, i want it to echo that var. But when i put the echo command in the code it is executed for every row. Where do I put the echo command in that code to make it run only once the var is all set?


-- HAMM3R (aka: alhammer)
http://www.HAMM3R.net