It is currently March 28th, 2024, 8:44 pm

Webparser not working because RegExp is too long

Get help with creating, editing & fixing problems with skins
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Webparser not working because RegExp is too long

Post by Virginityrocks »

Fetching weather codes from http://wxdata.weather.com/wxdata/search/search?where=Toronto. The Webparser pulls up to 10 weather codes and 10 location names from the xml. Toronto easily has 10 or more international locations by the same name, so the list fills to 10. If another name is entered, such as Yellowknife, with no other city by that name, the webparser doesn't pull any names or numbers. This is because the RegExp is trying to pull information from the xml that does not exist. I want the webparser to ignore data it cannot find, and pull what it can instead without any errors. How can this be done?

To test, change the Url= from where=Toronto to where=Yellowknife.

Code: Select all

[FetchWeatherCodes]
Measure=Webparser
Url=http://wxdata.weather.com/wxdata/search/search?where=Toronto
RegExp=(?siU)<loc id="(.*)".*type="1">(.*)</loc>.*<loc id="(.*)".*type="1">(.*)</loc>.*<loc id="(.*)".*type="1">(.*)</loc>.*<loc id="(.*)".*type="1">(.*)</loc>.*<loc id="(.*)".*type="1">(.*)</loc>.*<loc id="(.*)".*type="1">(.*)</loc>
UpdateRate=15
LogSubstringErrors=0
DynamicVariables=1

[Code1]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=1
DynamicVariables=1
Substitute="":"1"

[Location1]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=2
DynamicVariables=1
Substitute="":"1"

[Code2]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=3
DynamicVariables=1
Substitute="":"1"

[Location2]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=4
DynamicVariables=1
Substitute="":"1"

[Code3]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=5
DynamicVariables=1
Substitute="":"1"

[Location3]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=6
DynamicVariables=1
Substitute="":"1"

[Code4]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=7
DynamicVariables=1
Substitute="":"1"

[Location4]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=8
DynamicVariables=1
Substitute="":"1"

[Code5]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=9
DynamicVariables=1
Substitute="":"1"

[Location5]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=10
DynamicVariables=1
Substitute="":"1"

[Code6]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=11
DynamicVariables=1
Substitute="":"1"

[Location6]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=12
DynamicVariables=1
Substitute="":"1"

[Code7]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=13
DynamicVariables=1
Substitute="":"1"

[Location7]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=14
DynamicVariables=1
Substitute="":"1"

[Code8]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=15
DynamicVariables=1
Substitute="":"1"

[Location8]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=16
DynamicVariables=1
Substitute="":"1"

[Code9]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=17
DynamicVariables=1
Substitute="":"1"

[Location9]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=18
DynamicVariables=1
Substitute="":"1"

[Code10]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=19
DynamicVariables=1
Substitute="":"1"

[Location10]
Measure=Webparser
Url=[FetchWeatherCodes]
StringIndex=20
DynamicVariables=1
Substitute="":"1"
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Webparser not working because RegExp is too long

Post by balala »

Virginityrocks wrote:How can this be done?
In such cases the Lookahead Assertion can help. Replace the RegExp option of the [FetchWeatherCodes] measure with the following one:

Code: Select all

[FetchWeatherCodes]
...
RegExp=(?siU)(?(?=.*<loc).*id="(.*)".*type="1">(.*)</loc>)(?(?=.*<loc).*id="(.*)".*type="1">(.*)</loc>)(?(?=.*<loc).*id="(.*)".*type="1">(.*)</loc>)(?(?=.*<loc).*id="(.*)".*type="1">(.*)</loc>)(?(?=.*<loc).*id="(.*)".*type="1">(.*)</loc>)(?(?=.*<loc).*id="(.*)".*type="1">(.*)</loc>)(?(?=.*<loc).*id="(.*)".*type="1">(.*)</loc>)(?(?=.*<loc).*id="(.*)".*type="1">(.*)</loc>)(?(?=.*<loc).*id="(.*)".*type="1">(.*)</loc>)(?(?=.*<loc).*id="(.*)".*type="1">(.*)</loc>)