mIRC Homepage
Posted By: zotexa grab background image from html - 20/11/15 07:32 PM
Hey guys, I don't have much experience with mIRC scripting and so forth but I've been messing around and tweaking random scripts for an IRC channel me and some friends use.

Long story short, is there a way to grab the URL of the background image of a web page via mIRC scripts only? I was going to use a javascript one but js4mirc crashed mIRC so I don't think I'll be running that :p

Essentially the script I want is that when people type a certain command (in this case it'll be !m) it'll grab the background image of the website (which changes on every load) and post it into the channel.

We already had a script for it but the website we were using to get the images went down and the creator of the bot is inactive so I've been trying to recreate it myself to no avail. Any help is greatly appreciated!
Posted By: keyeslol Re: grab background image from html - 20/11/15 07:46 PM
This can be achieved using sockets, there is a fantastic tutorial here: http://mircscripting.info/forum/viewtopic.php?t=83&sid=8bca8f0c879dd35d0eb3bda8adbc3f00

Once you figure that out, you can output the url of the image to chat.
Posted By: zotexa Re: grab background image from html - 20/11/15 08:03 PM
That definitely seems like what I'd need but how would I configure it to grab only the background image? I don't want to grab the whole page, just the background image which isn't hosted on the site.
Posted By: argv0 Re: grab background image from html - 20/11/15 08:27 PM
By the way, js4mIRC wouldn't have helped you because it doesn't have any support for DOM access or making web requests. Sockets is the right approach. You want to make a web request for the page and, based on how the page is structured, either pull it from the associated CSS file or directly from HTML.

If you're programming this for a specific website, you may be able to shortcircuit a lot of those requests by making assumptions about where that background image URL is being stored (which CSS file, for instance). But if you're trying to make a generic function that can pull a background image from ANY website, note that this is actually not a trivial task and requires being able to parse the entire DOM, CSS, and in some cases, evaluate JavaScript. In other words, you need a full browser.

Note that someone may come in here and lend you a COM ($com) script to do this more easily, as $com() allows you to run an IE browser and pull information from the DOM. This is the foundation of SReject's JSON script, so if you are knowledgeable with COM / JS, you may want to look at that approach.
Posted By: FroggieDaFrog Re: grab background image from html - 20/11/15 11:02 PM
To clearify; my JSON script does not create an instance of an IE browser, nor create instances of the DOM or similar. It uses wscript.exe to access window's jscript engine, and various native libraries for making web requests when necessary.
--

As far as COM+DOM, this is QUITE difficult to do without creating a full instance of IE and then only limited information is available. I've tried a few times to make an html parser using an IE browser instance and there's roadblocks all along the way.
Posted By: argv0 Re: grab background image from html - 21/11/15 12:49 AM
I was referring to the foundation of using IE's COM objects. I think in my last attempt at this, it wasn't overly difficult. The "InternetExplorer.Application" object has a Navigate() method, at which point you should be able to access the Document property. You might have trouble hiding the window (I forget if it requires a visible window) but there are other ways to workaround that part.
© mIRC Discussion Forums