be forewarned when you start scraping content off webpages, you're gonna have to deal with handling the content as it exists in <HTML> form. in your case this might not be much of an issue the page you linked seems pretty straightforward.
here is a rough idea of a working example that has lots of notes so you can figure out what's going on. note that the user needs to have the proper case (e.g. colorSpray, chillTouch) with the search query.. or else the server will throw an error. this is by no means rock solid code but you can get some ideas about how the sockets are working with it.
on *:text:!spell*:#: {
getpaizocontent $chan $2
}
alias noHTML return $regsubex($1, /<[^>]+(?:>|$)|^[^<>]+>/g, $null)
alias getpaizocontent {
;; get content from "http://paizo.com/pathfinderRPG/prd/spells/"
;
; usage: /getpaizocontent $chan <searchquery>
;
; input: $1 %paizochan
; $2 %paizomark
;
; output: null => .msg $chan <result>
; let %paizochan be the room your nick is listening for !spell
set %paizochan $1
; let %paizomark be the spell name in: !spell <spellname>
set %paizomark $2
; close the <paizo> socket if it is already open
sockclose paizo
; open a <paizo> socket
sockopen paizo paizo.com 80
}
on *:sockopen:paizo: {
; write to the socket your HTTP header request...
sockwrite -nt $sockname GET /pathfinderRPG/prd/spells/ $+ %paizomark $+ .html HTTP/1.1
sockwrite -nt $sockname Connection: keep-alive
sockwrite -nt $sockname Host: paizo.com
sockwrite $sockname $crlf
}
on *:sockread:paizo: {
var %read
; let %startfind be the line of html right before your content starts
var %startfind class="stat-block-title"><b>
; let %endfind be the line of html where your content ends
; ..caution: this mIRCscript will break if this html changes..
var %endfind <div class = "footer">
sockread %read
; there was a weird quirk in the HTML of the paizo site resulting in
; a blank newline with the text '368' ... not really sure why this is
; happening. resolved with the below commands:
if ( $len(%read) < 10 ) && ( %paizofound = 1 ) {
unset %paizofound
unset %paizochan
unset %paizomark
sockclose paizo
halt
}
; typically if you wanted to close the socket you would listen for
; a string which would terminate your socket.. as shown below:
if ( %endfind isin %read ) {
sockclose paizo
unset %paizofound
unset %paizochan
unset %paizomark
halt
}
; %paizofound is defined underneath this - the %startfind was found on
; the previous line, so start dumping the contents of the page to your channel..
; defined initially as %paizochan
if ( %paizofound = 1 ) {
msg %paizochan $noHTML(%read)
}
; %startfind was found so set %paizofound to 1
if ( %startfind isin %read ) {
set %paizofound 1
}
}