1

Hello i'm having a script but when i try to catch info that i need i cant this is the part of html code that i would like to get:

<div class="pretty-container " >
2100.0
  </div>

So on my socket y try to do this to get the 2100.0(2100.0 it is a variable number):

on *:sockread:foo: {
 var %read
 sockread %read
 if ($regex(%read,<div class="pretty-container " >(.*)<\/div>)) {
    echo -s price founded: $regml(1)
    ; - here i try to catch the 2100.0 number
    sockclose $sockname
 }
}

but this doesn't work i believe it is because the number and are in another line. con some one helpme to solve this please?

thanks in advace,

Carlos

  • Not sure what that language is, but if it supports inline modifiers, you could try `(?s)` at the beginning of the expression. Otherwise, just replace the dot with `(?:.|\n|\r)`. On another note, you should be using a [non-greedy expression](http://stackoverflow.com/q/3075130), to sum it up, your expression might look like `
    ((?:.|\n|\r)*?)<\/div>`. For further optimisations, you might try to add `\s*` or `\s+` to match certain white-space dynamically.
    – HamZa Nov 24 '13 at 09:53

1 Answers1

1

The sockread command you use only reads one line at a time. Seeing as the data you're looking for is spread over multiple lines, your regular expression will never find a match.

A solution to this would be simply checking whether the current line contains <div class="pretty-container " >, and if so, store the data of the next line in another variable:

  var %read, %number
  sockread %read
  if (<div class="pretty-container " > isin %read) {
    sockread %number
    echo -s Number: %number
    sockclose $sockname
  }
Patrickdev
  • 2,341
  • 1
  • 21
  • 29