It is currently March 28th, 2024, 11:45 pm

New UserAgent option for WebParser

Changes made during the Rainmeter 4.0 beta cycle.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

New UserAgent option for WebParser

Post by jsmorley »

One thing you may very rarely run into when using WebParser to parse a website, is that the site reacts to the browser or program you are connecting with, and might format the output differently depending on what capabilities it assumes you have. This is done by the site using the User Agent String that is sent as part of the HTTP header when connecting.

WebParser uses a User Agent String of "Rainmeter WebParser plugin" when accessing a site. If you wish to connect to a site in Rainmeter using a different User Agent String, you can do this by using the new UserAgent option on the parent WebParser measure.

Example:

Code: Select all

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

[MeasureUserAgent]
Measure=Plugin
Plugin=WebParser
URL=https://www.whatismybrowser.com/detect/what-is-my-user-agent
UserAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36
RegExp=(?siU)<h1>What is my User Agent?.*<div class="value">(.*)</div>
StringIndex=1

[MeterUserAgent]
Meter=String
MeasureName=MeasureUserAgent
FontSize=10
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Note that I am not advocating using this approach to bypass checks that a site may do to "force" you to connect to it via a known browser, in order to ensure you at least are presented with advertising or other information displayed on the site. While this is very, very rare, it would be my opinion that this should be respected. "Spoofing" your User Agent String is in some sense being a "bad netizen", as it tends to throw off evaluations that are done on browser popularity either at a site or global level. This should only be used if you really need it for some specific purpose, and not as a general practice. 99.99% of sites could care less how you access them, and will work just fine and exactly the same with our default User Agent String for WebParser.