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:
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.
It is currently April 25th, 2024, 5:21 am
Line break into Webparser value
-
- Rainmeter Sage
- Posts: 16168
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Line break into Webparser value
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:
Skin:
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.
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>
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
You do not have the required permissions to view the files attached to this post.
-
- Rainmeter Sage
- Posts: 16168
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Line break into Webparser value
You're right, jsmorley, indeed this is the solution. You helped me again, thank you very much!
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Line break into Webparser value
Glad to help.
-
- Rainmeter Sage
- Posts: 16168
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Line break into Webparser value
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:
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
Code: Select all
RegExpSubstitute=1
Substitute="\n":"","^(.{0,3}).+$":"\1"
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
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Line break into Webparser value
In this case I see no need for a Substitute, just parse out exactly what you need:
Test.html:
Skin:
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.
Test.html:
Code: Select all
Value is (90.00%) right now
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
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.
-
- Rainmeter Sage
- Posts: 16168
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Line break into Webparser value
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.
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Line break into Webparser value
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.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.
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.
-
- Rainmeter Sage
- Posts: 16168
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Line break into Webparser value
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.
Thank you for your waste of time, jsmorley. You always help me, a simple Rainmeter skin creator and I'm grateful for this.