It is currently November 15th, 2019, 3:51 am

Getting images on web pages when they are "relative paths"

Tips and Tricks from the Rainmeter Community
User avatar
jsmorley
Developer
Posts: 19710
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Getting images on web pages when they are "relative paths"

jsmorley » June 23rd, 2009, 7:26 pm

I had run into an issue with retrieving and displaying images from web sites when the source HTML has them referred to as a "relative path" to the image.

As we all know, WebParser can download and display images by doing a WebParser Measure which gets the full URL and name of the image, and setting "Download=1" on the Measure. Then a Meter using Meter=IMAGE with a MeasureName=xxxx referring to the Measure which downloaded the image will display the downloaded image.

PROBLEM

The problem came in when the image was referred to in the web site HTML using a relative path to the image. An example is the logo at the top of the page here on the forums:

<a href="./index.php" title="Board index" id="logo"><img src="./styles/saphic/imageset/site_logo.png"/></a>

As you can see, the full URL is not included in anything that WebParser can search for, so Download=1 fails...

SOLUTION

A WebParser Measure can append the RESULTS of another WebParser Measure in the "URL" line by referencing the Measure in square brackets. This means you can use the first measure to return the name and location of the image you want, and use this information in a second Measure where you hard code the URL and then pass the result of the search for the image to the second Measure.

Best explanation is an example:

[MeasureImageLocation]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1800
Url=http://www.rainmeter.net/forum/
RegExp="(?siU)<img src="(.*)"/>"

[MeasureImageDownload]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1800
Url=http://www.rainmeter.net/forum/[MeasureImageLocation]
StringIndex=1
Download=1

[MeterDisplayImage]
Meter=IMAGE
MeasureName=MeasureImageDownload
H=60
W=70

Here we are using the first Measure [MeasureImageLocation] to get the relative path and filename of the image.

Then we use the second Measure [MeasureImageDownload] to combine the known URL and the information from [MeasureImageLocation] to create a fully loaded Measure which will succeed in downloading the image... Then we just display it.