It is currently October 15th, 2019, 9:44 am

Line break into Webparser value

Help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 8809
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Line break into Webparser value

balala » May 2nd, 2014, 4:24 pm

Hi all,

I have a network printer and with its IP address I can access a local webpage into the browser, which contains some information about the printer, like toner level. I'm working on a skin which could get (using the Webparser) some of these informations (like toner level) and show them. I wrote the measure, it works fine, but it seems that the returned information contains some line breaks. The measure returns this value:

Image

From this I need the numerical 100. The problem is those line breaks after NOWRAP> and before </TD> (before and after the needed 100), because if I modify the skin to show only the numerical value, this value contains linebreaks and a string meter show it this way:

Toner
100

despite that into the string meter I have this: Text=Toner: %1
In this case I can't use the parsed value into a bar meter (this would be the final purpose of the skin: to indicate continously the toner level, with a bar meter). I tried to create a button which write the parsed value as a variable (with WriteKeyValue) to can check it, but the returned variable's value is:

** </DD></TD><TD CLASS="elem" NOWRAP>100</TD></TR>

It seems that there is a table, but I can't figure out how to use the numerical value.
I can't indicate the web page I'd like to check, because it is just a local one, but if it would help I could save and upload it.
So, if you have any idea about how can get the numerical value, please help me.
User avatar
jsmorley
Developer
Posts: 19544
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Line break into Webparser value

jsmorley » May 2nd, 2014, 4:27 pm

You can use:

RegExpSubstitute=1
Substitute="\n":""

On the child WebParser measure returning that number value.

That will simply remove any linefeeds from the value.

Test.html:

Code: Select all

</DD></TD><TD CLASS="elem" NOWRAP>
100</TD></TR>
Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureSite]
Measure=Plugin
Plugin=WebParser
Url=file://#CURRENTPATH#Test.html
RegExp=(?siU)CLASS="elem" NOWRAP>(.*)</TD>

[MeasureValue]
Measure=Plugin
Plugin=WebParser
Url=[MeasureSite]
StringIndex=1
RegExpSubstitute=1
Substitute="\n":""

[MeterValue]
Meter=String
MeasureName=MeasureValue
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Toner: %1
2014-05-02_123330.jpg
Note that the vast majority of websites (and almost certainly in your case) are encoded in UTF-8 and use the Unix form of \n (linefeed) for the end-of-line character. If you are parsing a local file you created, it may well be in ANSI and encoded with the Windows form of \r\n (carriage return + linefeed) to end the line. You would want to adjust the Substitute accordingly to account for the carriage return if so.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 8809
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Line break into Webparser value

balala » May 2nd, 2014, 4:54 pm

You're right, jsmorley, indeed this is the solution. You helped me again, thank you very much!
User avatar
jsmorley
Developer
Posts: 19544
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Line break into Webparser value

jsmorley » May 2nd, 2014, 4:55 pm

Glad to help.
User avatar
balala
Rainmeter Sage
Posts: 8809
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Line break into Webparser value

balala » May 2nd, 2014, 6:33 pm

Please help me once again. One of the returned values is (90.00%), but I need 90. On a child measure, I tried to use this substitution:

Code: Select all

RegExpSubstitute=1
Substitute="\n":"","^(.{0,3}).+$":"\1"
but the returned value is (90 not 90. I tried to play with the {0,3} values and I could change the returned value into (9, or (90. but had no success to eliminate the first bracket. I suposed that the first number represent the begining of the result, but it isn't. The returned value don't depends on it. So, how can be eliminated the first character, the bracket?
And is anywhere a doc, which describes the Perl compatible regular expressions, because this isn't the first time I need to understand them, but I couldn't and I'd like to know more about them?

Thanks
User avatar
jsmorley
Developer
Posts: 19544
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Line break into Webparser value

jsmorley » May 2nd, 2014, 6:49 pm

In this case I see no need for a Substitute, just parse out exactly what you need:

Test.html:

Code: Select all

Value is (90.00%) right now
Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureSite]
Measure=Plugin
Plugin=WebParser
Url=file://#CURRENTPATH#Test.html
RegExp=(?siU)Value is \((.*)\.

[MeasureValue]
Measure=Plugin
Plugin=WebParser
Url=[MeasureSite]
StringIndex=1

[MeterValue]
Meter=String
MeasureName=MeasureValue
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Value: %1
2014-05-02_144452.jpg
RegExp=(?siU)Value is \((.*)\.

What we are doing is looking for "Value is (". The \( is required as the "(" character is reserved in regular expressions, so we "escape" it with the "\" character. Then we are capturing everything "(.*)" until we hit a "." character. Again, the "." character is reserved in regular expressions, so we escape it with the "\" character.

Reserved characters in regular expression are:

[ \ ^ $ . | ? * + ( )

There is tons of help for regular expressions at Resources for regular expressions.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 8809
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Line break into Webparser value

balala » May 2nd, 2014, 7:12 pm

This don't help, I tried this before, but with no success. I don't know why, but not works, that's why I started to thinking about a substitution. Without RegExpSubstitute (or RegExpSubstitute=0) I used a simple: Substitute="(":"",".00%)":"", but this don't works with RegExpSubstitute=1.
User avatar
jsmorley
Developer
Posts: 19544
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Line break into Webparser value

jsmorley » May 2nd, 2014, 7:39 pm

balala wrote:This don't help, I tried this before, but with no success. I don't know why, but not works, that's why I started to thinking about a substitution. Without RegExpSubstitute (or RegExpSubstitute=0) I used a simple: Substitute="(":"",".00%)":"", but this don't works with RegExpSubstitute=1.
That's not going to be reliable, as you don't know that it will be .00%. It might be .17% or something. Substitute is the wrong way to go here.

There is no reason why the RegExp I posted won't work. You need to give us a link to what you are parsing, or paste in the HTML, so we can see what is really going on.
User avatar
balala
Rainmeter Sage
Posts: 8809
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Line break into Webparser value

balala » May 2nd, 2014, 8:51 pm

In the meantime I found the solution: I had to enter a .* into the RegExp line and this, with your solution, helped.
Thank you for your waste of time, jsmorley. You always help me, a simple Rainmeter skin creator and I'm grateful for this.