Code:
 alias find.a.person { 
  if (!$isid) { 
    set %lastname $1 
    set %firstname $2 
    set %street.num $gettok($did(Observer,11),1,32)
    set %street.name $gettok($did(Observer,11),2-,32)
    set %apt $did(Observer,13)
    sockopen findap findaperson.canada411.ca 80 
  } 
} 
on *:sockopen:findap:{ 
  unset %match
  unset %page*
  sockwrite -n $sockname GET $+(/10649/search/Find_Person?firstname_begins_with=1&firstname=,%firstname,&name_begins_with=1&name=,%lastname,&city_zip=Sarnia&state_id=ON) HTTP/1.1 
  sockwrite -n $sockname Host: findaperson.canada411.ca $+ $crlf $+ $crlf 
} 
on *:sockread:findap:{ 
  if ($sockerr) { 
    echo -a some error occurred oh no. 
    return 
  } 
  else { 
    var %nc 
    sockread %nc 
    if ($+(*,%street.num,*,%apt,*,%street.name,*) iswm %nc) {
      var %nc = $right(%nc,20)
      var %nc = $left(%nc,14)
      did -ra Observer 15 %nc
      set %match found
    }
    elseif (*search_id* iswm %nc) && !%search_id {
      set %search_id $gettok(%nc,2,34)
      set %search_id $gettok(%search_id,-1,61)
    }
    elseif ($+(*,%lastname,*,%firstname,*,Total*) iswm %nc) {
      var %nc = $gettok(%nc,-2,32)
      var %nc = $gettok(%nc,-1,62)
      set %pages $calc($int($calc(%nc / 10)) + 1)
      set %pages $calc(%pages - 1)
    }
    elseif (</html* iswm %nc) || %match {
      sockclose findap
      /*
      if !%match && !%pages {
        inc %page
        sockopen findap $+ %page findaperson.canada411.ca 80
      }
      */
    }
  } 
}
/*
on *:sockopen:findap $+ %page:{
  set %limit $calc(%page * 10 + 1)
  sockwrite -n $sockname GET $+(/10649/search/Alpha_Limit?search_id=,%search_id,&old_search_type=Find_Person&sort=&alpha_limit=&lower=,%limit,) HTTP/1.1
  sockwrite -n $sockname Host: findaperson.canada411.ca $+ $crlf $+ $crlf 
}
on *:sockread:findap $+ %page:{
  if ($sockerr) { 
    echo -a some error occurred oh no. 
    return 
  } 
  else { 
    var %nc 
    sockread %nc 
    if ($+(*,%street.num,*,%apt,*,%street.name,*) iswm %nc) {
      var %nc = $right(%nc,20)
      var %nc = $left(%nc,14)
      did -ra Observer 15 %nc
      set %match found
    }
  }
  elseif (</html* iswm %nc) || %match {
    sockclose findap
    if !%match && !%pages {
      inc %page
      sockopen findap $+ %page findaperson.canada411.ca 80
    }
  }
} 
*/
 

That code works fine, even with the remarked areas as is, if the information that I want is on the first page from the website, however, there's a chance that it might not be, in which case I want to check all other pages until it comes across a match (presuming that there is a match). The remarked code is what I came up with, but it doesn't seem to work, as I've tested it with data that would be on the second of two pages, and the match isn't coming up. I'm not getting any error messages either.

Sample data to the site Smith, B in Sarnia, ON

Specific address that I was using for test purposes: 1423 Windemere Cres

Hopefully someone can correct my code so that the information is read correctly, no matter what page the site puts it on (site only puts 10 listings per page).

I would also appreciate an explanation of the changes that are made.

I know that part of the problem is getting the value for %search_id correct. It appears the location that I'm referencing is incorrect.

Edited: %search_id now returning correct value

Last edited by RusselB; 06/12/05 04:45 AM.