You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/tips/webparser-tutorial.html
+93-80Lines changed: 93 additions & 80 deletions
Original file line number
Diff line number
Diff line change
@@ -81,7 +81,7 @@ <h3>A quick example:</h3>
81
81
82
82
<h2>Our tutorial skin</h2>
83
83
84
-
<p>So what we are going to do today is parse a website <ahref="https://www.ipaddress.my/" target="blank">https://www.ipaddress.my/</a> to get our IP and location information to use in a skin. Click that link now if you want to open the page in a new tab/window.</p>
84
+
<p>So what we are going to do today is parse a website <ahref="https://browserleaks.com/ip" target="blank">https://browserleaks.com/ip</a> to get our IP and location information to use in a skin. Click that link now if you want to open the page in a new tab/window.</p>
85
85
86
86
<p>Here is what the web page we are going to parse looks like, with the information we are going to extract numbered:</p>
<p>If we search for <code>/images/flags/</code>, it will take us to the right place. What we want is the name of the file that follows<code>/images/flags/</code>. In this example, <code>us.png</code>.</p>
133
+
Ifwesearchfor<code>data-ip=</code>, it will take us to the right place. What we want is the IP Address that follows, enclosed in quotes. In this example, <code>68.100.86.32</code>.</p>
134
134
135
135
<p>Let's start building our <code>RegExp</code> option:</p>
136
136
137
137
``` html
138
138
[MeasureSite]
139
139
Measure=WebParser
140
-
URL=https://www.ipaddress.my/
141
-
RegExp=(?siU)<imgsrc="/images/flags/(.*)"
140
+
URL=https://browserleaks.com/ip
141
+
RegExp=(?siU)data-ip="(.*)"
142
142
UpdateRate=3600
143
143
```
144
144
145
145
<p>The important options are:</p>
146
146
147
-
<p><b>URL=https://www.ipaddress.my/</b> - The URL to the website. It can be set as a variable in the [Variables] section to make it easier to find and change if you want.</p>
147
+
<p><b>URL=https://browserleaks.com/ip</b> - The URL to the website. It can be set as a variable in the [Variables] section to make it easier to find and change if you want.</p>
148
148
149
-
<p><b>RegExp=(?siU)<img src="/images/flags/(.*)"</b> - Ah, the meat and potatoes...</p>
149
+
<p><b>RegExp=(?siU)data-ip="(.*)"</b> - Ah, the meat and potatoes...</p>
150
150
151
151
<p>You are telling RegExp to:</p>
152
152
153
-
<p>Use the (?siU) expression directives, (described earlier) search for <code><img src="/images/flags/</code> and capture everything to a StringIndex <code>(.*)</code> until it sees <code>"</code>, where it will stop.</p>
153
+
<p>Use the (?siU) expression directives, (described earlier) search for <code>data-ip="</code> and capture everything into a StringIndex <code>(.*)</code> until it sees <code>"</code>, where it will stop.</p>
154
154
155
155
<p>So if we look again at our output in WebParserDump.txt </p>
156
156
157
157
``` html
158
-
<imgsrc="/images/flags/us.png" border="0" height="48" width="48" alt="United States of America flag" align="absMiddle" /></li>
<p>You can see that we will return <code>us.png</code> in StringIndex 1</p>
161
+
<p>You can see that we will return <code>68.100.86.32</code> in StringIndex 1</p>
162
162
163
163
<p><b>UpdateRate=3600</b> - We want to check the website at a rate 3600 times the value in the "Update=" parameter in the "Rainmeter" section. As this defaults to "1000" or once every 1000 milliseconds (1 second) we will be running WebParser every 3600 seconds or 60 minutes. This is plenty often, as your IP information doesn't change much and you don't want to "spam" the website with requests. You may well find yourself blocked...</p>
164
164
165
165
<h2>The first child measure</h2>
166
166
167
167
<p>Then, we build a "child" measure, to grab that information from StringIndex 1 of the "parent" measure.</p>
168
168
169
-
<p>What we really want is not the file name of the flag image, but the image itself. WebParser can easily do this.</p>
170
-
171
-
<p>As long as the value from the parent measure that is returned in the StringIndex number is the URL to an image file, you can simply add the <code>Download=1</code> option to the child measure, and the image will be downloaded. The value of the child measure will then be the full <em>local</em> path to the file in the Windows TEMP folder Rainmeter will create.</p>
172
-
173
-
<p>However, wait.. the value "us.png" that is returned is not a full URL to the image. There is also a "relative path" to the image on the remote server. That's ok, we can still get the image.</p>
174
-
175
-
<h3>Creating the child measure for the the first StringIndex, the flag image value</h3>
169
+
<h3>Creating the child measure for the the first StringIndex, the IP Address value</h3>
<p>What we are doing is appending the first part of the URL, the one we used on the parent measure to the beginning of the <code>URL</code> option, followed by the relative path that flag images are stored in on the site, which is <code>/images/flags/</code> and a reference to [MeasureSite] and the <code>StringIndex=2</code> option. Then we add <code>Download=1</code> and that full URL of <code>https://www.ipaddress.my/images/flags/us.png</code> will be used to retrieve the image file.</p>
186
-
187
179
<p>The value of the child measure will in my case be:</p>
<p>Which we can use in an Image meter later to display it.</p>
183
+
<p>Which we can use in a String meter later to display it.</p>
192
184
193
185
<h3>Testing as we go</h3>
194
186
@@ -200,75 +192,72 @@ <h3>Testing as we go</h3>
200
192
201
193
<h2>The second child measure</h2>
202
194
203
-
<p>Now let's get the next bit of information we want from the website. (Remember, the RegExp reads the website in order from top to bottom, so you need to use the correct order in the "RegExp=" statement. You can display the information in any order you want on your skin however.)</p>
195
+
<p>Now let's get the next bit of information we want from the website. Remember, the RegExp reads the website in order from top to bottom, so you need to use the correct order in the "RegExp=" statement. You can display the information in any order you want on your skin however.</p>
204
196
205
-
<p>The next information in the WebParserDump file that we want is the IP address for your computer that the site detects:</p>
197
+
<p>The next information in the WebParserDump file that we want is the flag image for your detected country:</p>
<p>What we really want is not the file name of the flag image, but the image itself. WebParser can easily do this.</p>
213
203
214
-
<p>So we want to add to our "RegExp=" statement, search for th IP address, and return the result in the next StringIndex on the parent measure:</p>
204
+
<p>As long as the value from the parent measure that is returned in the StringIndex number is the URL to an image file, you can simply add the Download=1 option to the child measure, and the image will be downloaded. The value of the child measure will then be the full local path to the file in the Windows TEMP folder Rainmeter will create.</p>
215
205
216
-
``` ini
206
+
We will modify our RegExp statement to get the flag data into a second StringIndex:
<p>However, wait.. the value <b>/img/flags/US.png</b> that is returned is not a full URL to the image. There is also a "relative path" to the image on the remote server. That's ok, we can still get the image.
227
218
228
-
<p>This will tell RegExp to skip everything until it finds <code><td width="40%">IP Address:</td>.*target="_blank"></code> and then capture everything until it sees <code><</code> and put it in <code>StringIndex=2</code>. The result in my example will be <code>68.100.86.32</code>.</p>
229
-
230
-
<h3>Creating the child measure for the the second StringIndex, the IP address value</h3>
219
+
Creating the child measure for the the second StringIndex, the flag image value
231
220
232
221
``` ini
233
-
[MeasureIP]
234
-
Measure=WebParser
235
-
URL=[MeasureSite]
236
-
StringIndex=2
222
+
[MeasureFlagImage]
223
+
Measure=Plugin
224
+
Plugin=WebParser
225
+
URL=https://browserleaks.com[MeasureSite]
226
+
StringIndex=2
227
+
Download=1
237
228
```
238
229
230
+
What we are doing is appending the first part of the URL, the one we used on the parent measure to the beginning of the URL option, followed by the relative path that flag images are stored in on the site, which is /img/flags/ and a reference to [MeasureSite] and the StringIndex=2 option. Then we add Download=1 and that full URL of https://browserleaks.com/img/flags/US.png will be used to retrieve the image file.
231
+
232
+
The value of the child measure will in my case be:
<p>This will tell RegExp to skip everything until it sees <code><td>City:</td>.*<td></code> then capture everything until it sees <code></td></code> and put it in <code>StringIndex=3</code>. The result in my example will be <code>Fairfax</code>.</p>
264
-
265
253
<h3>Creating the child measure for the the third StringIndex, the city name value</h3>
0 commit comments