It is currently May 21st, 2024, 10:52 pm

Reading a number with WebParser

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

Reading a number with WebParser

Post by balala »

Hello,

I'd like to read some information from a webpage with WebParser. On the webpage sometimes appeares this line:
<TD width="60%" bgColor=#ffffff title=40%>&nbsp;</TD> - the bold number should be read.
Other times two similar lines:
<TD width="40%" bgColor=#00ffff title=40%>&nbsp;</TD>
<TD width="60%" bgColor=#ffffff title=40%>&nbsp;</TD> - here also the bold number should be read.
If I'm using this RegExp: <TD width="(.*)%" bgColor=#ffffff, can I determine somehow the WebParser to read always just the number which appeares befor the percent sign? Because in the second case two lines of string are readed, instead of the number.

Thank you
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Reading a number with WebParser

Post by MerlinTheRed »

If you don't explicitly set your RegExp to be ungreedy by adding (?U) to the start of the RegExp or by using (.*?) instead of (.*), it will always match as much as it can. In the second case, everything after the first "<TD width=" until the last "%" bgColor=#ffffff".

Try this one: "<TD width="(\d+)%" bgColor=#ffffff". The \d matches only digits. \d+ means one or more digits.
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
balala
Rainmeter Sage
Posts: 16252
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Reading a number with WebParser

Post by balala »

Thank you very much, that was the solution I looked for, it helped indeed.