mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2006
Posts: 22
S
schism Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: May 2006
Posts: 22
I have a lot of links on a website I'm parsing through sockets, each link has the same params followed by a differnet number.

For example:

<a class="name" href="http://blah.com/page.cgi?action=dothat4&param=396533245" onclick="return junk">

<a class="name" href="http://blah.com/page.cgi?action=dostuff1&param=634563" onclick="return junk">

and so on, what would be the most efficient way of pulling the number from a URL such as that when action (dostuff1, dothat4) changes depending on the URL, and the numbers change somewhat as well (but the param= does not). I'm thinking I have to find the position of param= pull all text until the next " but I am not sure exactly how to do it, any suggestions?

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Below assumes %url holds the url and it has both fields in it. Also action= has only a 1 digit number ending it

var %action = $gettok($mid(%url,$calc($pos(%url,action=,1) + 7)),1,$asc(&))
var %action.word = $left(%action,-1)
var %action.number = $right(%action,1)
var %param = $gettok($mid(%url,$calc($pos(%url,param=,1) + 6)),1,$asc("))

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Assuming the format you gave...

$gettok($gettok([color:green]The-line-to-parse,4,34)[/color],3,61)

The blue part is grabbing the url portion of the line (http://...) which is 4th token that is separated by " (ascii value 34). The red part takes from the blue part, the 3rd token that is separated by = (ascii value 61), which is the number you want.

I assume that the characters " and = do not show up in your dostuff anywhere, else this will not work correctly.

As an example:

Code:
alias getnum {
  var %n = &lt;a class="name" href="http://blah.com/page.cgi?action=dostuff1&amp;param=634563" onclick="return junk"&gt;
  echo -a $gettok($gettok(%n,4,34),3,61)
}

Joined: May 2006
Posts: 22
S
schism Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: May 2006
Posts: 22
Quote:
Assuming the format you gave...

$gettok($gettok([color:green]The-line-to-parse,4,34)[/color],3,61)

The blue part is grabbing the url portion of the line (http://...) which is 4th token that is separated by " (ascii value 34). The red part takes from the blue part, the 3rd token that is separated by = (ascii value 61), which is the number you want.


Thanks, that worked well,

Is there a variable (or $chr?) that represents a return... I'm writing an HTML file with the script and would like the source to be all "pretty" and formatted.


Also, is there a raw for creating error messages for sockets? For example I can give a custom error when I get
/sockwrite: 'profiles' not connected (line 56, Check-profiles.mrc)

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
For a return, you can use $crlf.

As for the raw, I do not know. I've never had a need to use sockets, so I don't know of any raws in regards to them. You can find out by typing:

/debug @debug
Deliberately try to do an action while not connected and see what comes up in the debug window.

Joined: May 2006
Posts: 22
S
schism Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: May 2006
Posts: 22
Quote:
As for the raw, I do not know. I've never had a need to use sockets, so I don't know of any raws in regards to them. You can find out by typing:

/debug @debug
Deliberately try to do an action while not connected and see what comes up in the debug window.


Yeah, I tried, nothing showed up, which is why I came here to ask.

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
mIRC RAW events have nothing to do with sockets. The /debug command only shows data that is related to mIRC's built-in IRC-connection code. The only events that are related to sockets are the onSOCK* events (onSOCKOPEN, onSOCKREAD, etc). All events are shown in /help sockets

To make custom error messages, you need to do all the checks yourself and echo errors manually. Example:

if (!$sock(socketname)) echo -s Socket Error: socketname is not connected.

-genius_at_work


Link Copied to Clipboard