mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2013
Posts: 7
R
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: Oct 2013
Posts: 7
i'm working on a script for a friend (and to help me learn how sockets work)
Code:
alias city {
  sockopen city mcfc.co.uk 80
}

on *:sockopen:city: {
  sockwrite -n $sockname GET /News/Club-news HTTP/1.1
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
  sockwrite -n $sockname Host: mcfc.co.uk
  sockwrite -n $sockname Accept-Language: en-us
  sockwrite -n $sockname Accept: */*
  sockwrite -n $sockname
}

on *:sockread:city: {
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %temp
    sockread -f %temp
    if (<span class="cl-main"> isin %temp) {
      echo -a %temp
      halt
    }
  }
}

This returns the 10 <span> tags but no content.
Code:
<span class="cl-main">
	<span class="cl-main">
	<span class="cl-main">
	<span class="cl-main">
	<span class="cl-main">
	<span class="cl-main">
	<span class="cl-main">
	<span class="cl-main">
	<span class="cl-main">
	<span class="cl-main">


What i want to get is the content between the opening and closing span tags.
How can i achieve this? thanks in advance

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
You're reading one line at a time and the content is on another line. You can save everything to a file then $read at the end, or parse it as it comes in and keep counters to know which line the data's on. Also, you halt isn't doing anything.

Joined: Oct 2013
Posts: 7
R
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: Oct 2013
Posts: 7
Code:
on *:sockread:city: {
  if ($sockerr) {
    echo -a Error.
      }
  else {
    var %temp
    sockread -f %temp
    if (<span class="span-h5"> isin %temp) {
      echo -a %temp
      halt
    }
  }
}

I've changed the span class to the correct one where the content is.
How do I parse it? Regex, Replace etc?
I understand PHP fairly well so if its a similar function I'll pick it up quickly its just learning the first step

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
That opening span is still a line above, you'll need to sockread again. If the span is the last line in the buffer at the time and the event retriggers you'll need to keep track of this fact with a variable.

So you might upon finding the span-h5, set a variable: "set %span-h5 1", on your next read you check if (%span-h5 == 1) then you know the line you're reading is the content you're looking for. unset %span-h5 and strip out the whitespace before the content with regex: %temp = $regsubex(%temp,^\s+,)

If the content you're looking for is more than one line away set your variable to the number of lines, keep a counter for how many more lines you've read, and compare them to know when you're on the line with the content you want.


Link Copied to Clipboard