mIRC Homepage
Posted By: Stefan_Leroux Wildcards in variables? - 15/04/07 01:59 PM
Hey Guys, I'm looking for a bit of help with setting variables.

I'm trying to make a script to check my status on a web page.

The web page displays in this format

<div class="divclass">info goes in here</div><div class="divclass2">more info goes in here</div>

I have already created a script to obtain the html from the page, but I need some way to set the information into variables. I need to know if its possible to set a variable starting after the <div class="divclass"> and ending at the </div>, or even to set the entire variable and $remove the div classes. I've used this method before, but because of this web-page the class doesnt start at the beginning of the line, so I cant just set the entire line as the variable and $remove, because theres too many variables in the line.

Thanks
Posted By: PhantasyX Re: Wildcards in variables? - 15/04/07 02:15 PM
Something that might help you (I DID NOT CREATE this identifier, I do not claim I did. I picked it up myself from another script a long time ago.)

alias nohtml { var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, ) | return %x }

This command will remove the HTML tags.
So therefore turning "<div class="something">Hello There</div>"
info "Hello There".

$nohtml(<html><span>Text Here.</span></html>) = Text Here. =p
Posted By: Stefan_Leroux Re: Wildcards in variables? - 15/04/07 06:23 PM
Well, not quite what I need at this point. That will still leave me with lots of bunk and not just the litlle bit i need.

I wish the site was a cleaner layout, but well, its not mines frown.

But HTML remover is perfect for other stuff, so cheers anyway mate.
Posted By: Riamus2 Re: Wildcards in variables? - 15/04/07 09:24 PM
You usually need to use tokens to handle text from sites. Use $gettok to get what you're trying to out of a line of text.
Posted By: genius_at_work Re: Wildcards in variables? - 16/04/07 04:55 AM
You should be able to use regex to use to get any info you need.

Code:
var %in = <div class="divclass">info goes in here</div><div class="divclass2">more info goes in here</div>
noop $regex(div,%in,/<div class="divclass">(.*?)</div>/i)
var %var1 = $regml(div,1)


(regex untested)

-genius_at_work
© mIRC Discussion Forums