The following example extracts a specified price from a web page and triggers a notification only if the price is lower than a predefined value.

The price extraction depends on the structure of the page. You can use the code below as a starting point and adapt it to the HTML structure of your target page.


An alternative to such a Plugin is the regexcmp function. It can be used in Ignore filters, Watch filters, and in the Keywords functionality.


Sub ExtractPrice($sMem, ByRef $nPrice)
   
   Dim $p, $nLen
   
   $nPrice = -1
   $sMem = DeleteHtmlTags($sMem)
   ' Extract price without decimal places
   If FindRegex($sMem, "Price:\s*EUR\s*\d+,", $p, $nLen) Then
      $sMem = ExtractDigits(Copy($sMem, $p, $nLen))
      $nPrice = CInt($sMem)
   End If
End Sub

'*******************************************************************************

Sub Wsw_CompareVersions(ByRef $sMemWeb, ByRef $sMemLocal, ByRef $sStatusMessage, ByRef $iStatusCode)
   
   Dim $nPriceNew, $nPriceOld, $nPriceRef
   
   ' Define reference price (100 EUR)
   $nPriceRef = 100
   
   ' Extract price from new/local version
   ExtractPrice($sMemWeb, $nPriceNew)
   ExtractPrice($sMemLocal, $nPriceOld) ' only needed to speed up several WSW routines
   
   ' Return only price - speed up several WSW routines, eg. "Test filter" dialog or "Analyze" functionality
   $sMemWeb = CStr($nPriceNew)
   $sMemLocal = CStr($nPriceOld)
   
   If $nPriceNew = -1 Then
      $iStatusCode = 2
      $sStatusMessage = "Error extracting price"
   ElseIf ($nPriceNew <> $nPriceOld) And ($nPriceNew <= $nPriceRef) Then
      $iStatusCode = 1
      $sStatusMessage = "Price changed and lower than EUR " + CStr($nPriceNew)
   ElseIf ($nPriceNew <> $nPriceOld) And ($nPriceNew > $nPriceRef) Then
      $iStatusCode = 0
      $sStatusMessage = "Price too high"
   Else
      $iStatusCode = 0
      $sStatusMessage = "Price unchanged"
   End If
End Sub