It is currently March 29th, 2024, 3:31 pm

[Solved] Webparser and string.match

Discuss the use of Lua in Script measures.
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

[Solved] Webparser and string.match

Post by FreeRaider »

Hello all, I have this situation.

Using webparser for parsing an URL, I can get two results:
a) <div id="text-content" data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1"><div id="text" dir="auto" data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1.2"><h3 class="text-restricted" data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1.2.0">Unfortunately we're not authorized to show these texts.</h3><img src="//tracking.newco.com/t1.0/m_img/e_0/sn_0/l_7768761/su_0/tr_JXFcUSmLGm3tRMZTMDpU1YysJ14YRO42rd5xpbb224wiCxEmd1oVzfjkWLKAM/VGUHVL6cRCMWwiKcjX5EqD5kTjtZ/IEhvrqNqVM4Oyi80eI43w+r/Lu4w1McMmqSA/ttmHfD+KSMjNyQf9c064l6ARS/JJSBkLLKwBXGwDseXkptsZT8cyAzWsige/nRNrO3e59TFUSmgpyzIHkL4hqIrLJaS4Me+WV/OYpf6NL3VjF3vyqUtVnfhnMQD/X8lQ//iqBRIYdm5iHPrFhiqC0W3Sd/HBpbzHDoVF4as3dtuy7t58FKxLfsUrKnzK1QGsiorD9b2X4M9ikl4hoWpzFAsgEChI9kEAJvFlS5eLxZi3MrlKNyzlciTRbKG8HY7hWbO72Pke+/o3nAu7K0aIHZsJkKWhxsHUnKWIKGN5flMLI/WxE7cjUSP+7uSp04xcRcoHkCq3Ny3/dLK3utrwFw==/" data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1.2.1" style="display: none !important;"></div></div>

b) <div id="text-content" data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1"><noscript data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1.0"></noscript><div id="text" dir="auto" data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1.2"><div data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1.2.0"><div id="selectable-text" class="body" data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1.2.0.0"><div data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1.2.0.0.0"><span id="l6357" data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1.2.0.0.0.$text-body">This is a long text for example1
This is a long text for example2
This is a long text for example3
This is a long text for example4

This is a long text for example5
This is a long text for example6
This is a long text for example7
This is a long text for example8

This is a long text for example9</span><span data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1.2.0.0.0.1"></span></div></div></div><img src="//tracking.newco.com/t1.0/m_img/e_0/sn_0/l_13309263/su_0/tr_v8AvA0OtLueVi8CEsmZPvxR7AhtPZag7GpQMYYDVFzIQ2jg8oVIJmLKDiFRSgGkLHA0yrHoTFP7G7GBi8i/DWB8kcJK5eFd+OlnXzNVVuHIkAVDa8Bb20Z9mI+XybxHqwMDiUlZ90EGCrmhKvrnFQATjHGKyAi/DdE+YiCK7GkfLVinvuUGcaE3wtkpXxJGkXdfzH839C2ko7iH8nHKnGlugQcry0ra94dyNlOmw4dTwslXtXg8YjB7q1DiGfUL3Zeikv0wDD6+JIx1XiIgABEJ3a/D2tvW6fYZWcWThqq01tfSecINUf1htGzObejCzrZEm0Al9DuvghAb25MGMf1rbSvuvHvfasHDV9oiFUrsZajWFw6Rss05ge1OFYghRT5P6IosMVQsktp8k6qmKA6nTO4ESRvh99y4rzVOMkgmhAapkb4Nf+Yv6R1RD9b6DTfTunu4BNvhkbhkyj6OHvA==/" data-reactid=".olvb8xc740.1.2.0.0.0.2.0.1.2.1" style="display: none !important;"></div></div>
Now, I have create this file .lua

script.lua

Code: Select all

function Initialize()

	msMeasureGetText = SKIN:GetMeasure('MeasureGeText')
	
end
	

function Update()


	sText = msMeasureGetText:GetStringValue()

        sTextString = string.match(sText, ".-text%-restricted\".->(.-)<.-") or string.match(sText, ".-text%-body\">(.-)<.-") 
	
        SKIN:Bang('!SetOption', 'MeterText', 'Text', sTextString)

			
end
but it freezes Rainmeter and I have to use the task manager to close it.

How can I solve?

Thanks in advance
Last edited by FreeRaider on March 6th, 2016, 1:23 pm, edited 2 times in total.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Webparser and string.match

Post by smurfier »

Code: Select all

function Initialize()
   sMeasureGetText = SKIN:GetMeasure('MeasureGeText')
end
   

function Update()
	sText = msMeasureGetText:GetStringValue()
	sTextString = string.match(sText, '<h3 class="text%-restricted"[^>]*>([^<]*)<') or string.match(sText, '%$text%-body">([^<]*)<') 
	SKIN:Bang('!SetOption', 'MeterText', 'Text', sTextString or "")
end
Also, set your script measure to UpdateDivider=-1 and have it update using FinishAction=[!UpdateMeasure "YourScriptMeasure" "#CURRENTCONFIG#"]
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Webparser and string.match

Post by FreeRaider »

Thank you smurfier, it works except for the SKIN:Bang, the text does not appear.

MeterText is

Code: Select all

[MeterText]
Meter=String
X=0
Y=0
I don't understand why :confused: :confused:
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Webparser and string.match

Post by FreeRaider »

I understand. I forgot to set "DynamicWindowSize = 1" under [Rainmeter] section.