It is currently April 27th, 2024, 7:29 pm

RegExp/ WebPasrser- Is this accurate?

Get help with creating, editing & fixing problems with skins
SysMunky
Posts: 9
Joined: December 29th, 2012, 8:19 pm

RegExp/ WebPasrser- Is this accurate?

Post by SysMunky »

I'm planning on making a little skin that will essentially read some stats from a website I am working to understand how to use the web parser and regexp. As a start, I have attempted to obtain the total battles participated and display it.

Code: Select all

[RainMeter]
Update=1000
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,0,0,255


[mParent]
Measure=Plugin
Plugin=WebParser
URL=http://worldoftanks.com/community/accounts/1000518504

-SysMunky/
RegExp="(?siU)<table>.*<tr>.*<td>.*<table>.*<tr>.*</tr>.*<tr>.*<td>.*</td>.*<td>(.*)</td>"

[mBattlePartic]
Measure=Plugin
Plugin=WebParser
URL=[mParent]
StringIndex=1


[MeterBatPartLbl]
Meter=String
FontSize=10
FontColor=222,255,227,255
X=10
Y=10
Text="Battles:"

[metBatPart]
Meter=String
Y=20r
X=50r
MeasureName=mBattlePartic
FontSize=10
FontColor=222,255,227,255
AntiAlias=1
At this point I know it is not working right, which means my understanding is definitely wrong. I also suspect that there may be a much more simplified way to get the information I am trying to find. Thoughts or guidance appreciated.

edit: Noticed I had RegExp= "(siU)...." instead of RegExp= "(?siU)..." but I haven't resolved the existing issue, yet.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: RegExp/ WebPasrser- Is this accurate?

Post by eclectic-tech »

Code: Select all

[RainMeter]
Update=1000
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,0,0,255

[mParent]
Measure=Plugin
Plugin=WebParser
URL="http://worldoftanks.com/community/accounts/1000518504-SysMunky/"
RegExp="(?siU)<td><span>Battles Participated</span></td>.*<td class="right value">(.*)</td>.*"
StringIndex=1

[mBattlePartic]
Measure=Plugin
Plugin=WebParser
URL=[mParent]
StringIndex=1

[MeterBatPartLbl]
Meter=String
MeasureName=mBattlePartic
FontSize=10
FontColor=222,255,227,255
X=10
Y=10
W=80
H=25
Text=Battles: %1
Put URL= all on 1 line...
Changed the RegExp=...
Added the measurename to the first String meter and removed the second unneeded meter

The text "Battles Participated" occurs 4 times in the source code...
the 2nd occurrence seems the simplest to parse.

We look for the unique section <td><span>Battles Participated</span></td> then tell the parser to copy nothing .* until it
sees <td class="right value"> then copy everything (.*) up to the </td> then copy nothing .*

This returns the number of battles.

I would suggest using RainRegExp.exe tool developed by JSMorley to help you parse webpages... it's a great learning tool!
SysMunky
Posts: 9
Joined: December 29th, 2012, 8:19 pm

Re: RegExp/ WebPasrser- Is this accurate?

Post by SysMunky »

Thank you! Your explanation made a lot more sense than a lot of what I had been able to find in my searches (and confusing attempts at understanding all the documentation). I was able to successfully create a rather sloppy working version after a ridiculous amount of trial and error, albeit a very sloppy, ugly, and poorly styled skin that i actually fear to return to finish. Given better understanding now, perhaps I wil start fresh and see if I can make something halfway pleasant.

One thing that I am puzzled by is that when i was looking at the source for the site, I see <td-class-number-nowidth">whereas you have <td class="right value"> Do you by chance know why these would be different?

Thanks again!
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: RegExp/ WebPasrser- Is this accurate?

Post by eclectic-tech »

SysMunky wrote:Thank you! Your explanation made a lot more sense than a lot of what I had been able to find in my searches (and confusing attempts at understanding all the documentation). I was able to successfully create a rather sloppy working version after a ridiculous amount of trial and error, albeit a very sloppy, ugly, and poorly styled skin that i actually fear to return to finish. Given better understanding now, perhaps I wil start fresh and see if I can make something halfway pleasant.

One thing that I am puzzled by is that when i was looking at the source for the site, I see <td-class-number-nowidth">whereas you have <td class="right value"> Do you by chance know why these would be different?

Thanks again!
It depends on which of the 4 occurrences of "Battles Participated" you want to parse. The first 2 occurrences both give the number of battles. The difference is you used the first occurrence while I chose to parse the second to get the number of battles...

The first occurrence has the prefix you give, the 2nd occurrence has a different prefix code; the one I used.
User avatar
ScoobSTi
Posts: 127
Joined: September 12th, 2012, 10:49 pm

Re: RegExp/ WebPasrser- Is this accurate?

Post by ScoobSTi »

Check out this extremely useful tool by JSMorley called RainRegExp. It lets you test the website and RegExp values that you're trying to parse. It helped me a lot because I didn't know a thing about RegExp, but now I feel more confident in getting my own codes, rather than using existing ones from skins like Gnometer, Illustro, etc.
Image