It is currently May 10th, 2024, 6:44 am

Recursive download method

Tips and Tricks from the Rainmeter Community
User avatar
kenz0
Developer
Posts: 263
Joined: July 31st, 2009, 2:23 pm
Location: Tokyo, JPN

Recursive download method

Post by kenz0 »

WebParser can get any information from specified webpage by the user. However, is it possible to get information from the linked page on the page?

Yes, It is possible if Rainmeter is version 1.2. (also beta or later)

-----------------------------------------------------------------

First example tries to extract URL of a top entry (Blog posts) on linked pages from the top of Google Trends.


Process 1: Access RSS of Google Trends and parse the top link.

Code: Select all

[SOURCE-0]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=3600
Url=http://www.google.com/trends/hottrends/atom/hourly
RegExp="<a href=\"(.*?)\">(.*?)<"
Process 2: Download parsed link URL to DownloadFile's folder as "src1.html" by using new function "DownloadFile".

Code: Select all

[SOURCE-1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[SOURCE-0]
StringIndex=1
Download=1
DownloadFile=src1.html
FinishAction=!RainmeterEnableMeasure SOURCE-2
Process 3: When download of "src1.html" is finished, [SOURCE-2] section becomes enable, and the parsing of "src1.html" is started.

Code: Select all

[SOURCE-2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url="file://#CURRENTPATH#DownloadFile\src1.html"
RegExp="<a class=\"gs-title\" href=\"(.*?)\""
FinishAction=!RainmeterDisableMeasure SOURCE-2
Disabled=1
In order not to continue unnecessary parsing, it is important to make [SOURCE-2] section disable after completing parsing.


Finally: URL parsed by [SOURCE-2] section is referred to with [LINK] section.

Code: Select all

[LINK]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[SOURCE-2]
StringIndex=1
Full code is here.
[SOURCE-0]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=3600
Url=http://www.google.com/trends/hottrends/atom/hourly
RegExp="<a href=\"(.*?)\">(.*?)<"

[TITLE]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[SOURCE-0]
StringIndex=2

[SOURCE-1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[SOURCE-0]
StringIndex=1
Download=1
DownloadFile=src1.html
FinishAction=!RainmeterEnableMeasure SOURCE-2

[SOURCE-2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url="file://#CURRENTPATH#DownloadFile\src1.html"
RegExp="<a class=\"gs-title\" href=\"(.*?)\""
FinishAction=!RainmeterDisableMeasure SOURCE-2
Disabled=1

[LINK]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[SOURCE-2]
StringIndex=1

[MeterString]
Meter=STRING
MeasureName=TITLE
X=0
Y=0
W=200
H=16
SolidColor=FFFFFF
AntiAlias=1
ClipString=1
LeftMouseUpAction=!Execute [[LINK]]
-----------------------------------------------------------------

Next example traces the link from RSS of customize.org and is the way to get an original wallpaper image.


Process 1: Access RSS feed and download first link to DownloadFile's folder as "src1.html" and then start [SOURCE-1] section.

Code: Select all

[SOURCE-0]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=3600
Url=http://customize.org/feeds/category/wallpapers
RegExp="(?sU)<item>.*<link>(.*)<"
StringIndex=1
Download=1
DownloadFile=src1.html
FinishAction=!RainmeterEnableMeasure SOURCE-1
Process 2: Parse "src1.html" then extract URL of "Download" page.

Code: Select all

[SOURCE-1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url="file://#CURRENTPATH#DownloadFile\src1.html"
RegExp="(?sU)class=\"download\".*href=\"(.*)\""
Disabled=1
Process 3: Download "Download" page to DownloadFile's folder as "src2.html" and then start [WALLPAPER] section.

Code: Select all

[SOURCE-2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=http://customize.org[SOURCE-1]
StringIndex=1
Download=1
DownloadFile=src2.html
FinishAction=!Execute [!RainmeterDisableMeasure SOURCE-1][!RainmeterEnableMeasure WALLPAPER]
Process 4: Parse "src2.html" and extract URL of original wallpaper, and then download it.

Code: Select all

[WALLPAPER]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url="file://#CURRENTPATH#DownloadFile\src2.html"
RegExp="(?sU)wallpaper details<.*img src=\"(.*)\""
StringIndex=1
Download=1
DownloadFile=wp.jpg
FinishAction=!RainmeterDisableMeasure WALLPAPER
Disabled=1
Finally: Original wallpaper is downloaded to DownloadFile's folder as "wp.jpg".

Full code is here.
[SOURCE-0]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=3600
Url=http://customize.org/feeds/category/wallpapers
RegExp="(?sU)<item>.*<link>(.*)<"
StringIndex=1
Download=1
DownloadFile=src1.html
FinishAction=!RainmeterEnableMeasure SOURCE-1

[SOURCE-1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url="file://#CURRENTPATH#DownloadFile\src1.html"
RegExp="(?sU)class=\"download\".*href=\"(.*)\""
Disabled=1

[SOURCE-2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=http://customize.org[SOURCE-1]
StringIndex=1
Download=1
DownloadFile=src2.html
FinishAction=!Execute [!RainmeterDisableMeasure SOURCE-1][!RainmeterEnableMeasure WALLPAPER]

[WALLPAPER]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url="file://#CURRENTPATH#DownloadFile\src2.html"
RegExp="(?sU)wallpaper details<.*img src=\"(.*)\""
StringIndex=1
Download=1
DownloadFile=wp.jpg
FinishAction=!RainmeterDisableMeasure WALLPAPER
Disabled=1

[MeterWallpaper]
Meter=IMAGE
MeasureName=WALLPAPER
X=6
Y=6
W=180
SolidColor=00000055
LeftMouseDoubleClickAction=!Execute ["[WALLPAPER]"]
-----------------------------------------------------------------

The feature of this method is to parse it after downloading the source to a local folder. If such a processes is repeated step-by-step, it is possible to retrieve information even from the page of deep structure.
Last edited by kenz0 on August 3rd, 2010, 3:45 am, edited 1 time in total.
.
Image
User avatar
~Faradey~
Posts: 366
Joined: November 12th, 2009, 4:47 pm
Location: Ukraine

Re: Recursive download method

Post by ~Faradey~ »

This is very usefull information...i was thinking how to do it in version 1.1..and stuck in the middle :(
but with this i can finally finish one of my youtube skins \o/

Tnx a lot kenz0