Tema: 403 error
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/03/2015, 19:32
Avatar de Maganius
Maganius
 
Fecha de Ingreso: septiembre-2010
Mensajes: 310
Antigüedad: 13 años, 6 meses
Puntos: 10
403 error

Wenas,,

Tengo un programa el cual recolecta jugadores de una página web.

El problema es que al realizar un for e intentar recoger datos del jugador la página me devuelve:

failed to open stream: HTTP request failed! HTTP/1.0 403

Esto me sucede despues de mandar cierta cantidad de peticiones, al principio no sucece.

El PHP:

Código PHP:
Ver original
  1. $deaths = $t->characterDeaths($core->fixName($row["name"]));        
  2.         foreach($deaths as $d)
  3.         {    
  4.             if($d["level"]!="")
  5.             {
  6.                 $info = array(
  7.                     "char_id"=>$row["id"],
  8.                     "fecha_muerte"=>strtotime(date_format($d["date"],"d-m-Y H:i:s")),
  9.                     "level"=>$d["level"],
  10.                     "reason"=>$d["reason"]
  11.                 );
  12.                 $core->Deaths($info);
  13.             }
  14.         }

La clase:

Código PHP:
Ver original
  1. public function characterDeaths($name)
  2.     {
  3.         $html = file_get_contents("xxxx&name=".$name);
  4.  
  5.         if (false !== stripos($html, "<b>Could not find character</b>")) {
  6.             throw new CharacterNotFoundException($name);
  7.         }
  8.  
  9.         $domd = $this->getDOMDocument($html);
  10.         $domx = new \DOMXPath($domd);
  11.         $rows = $domx->query("//b[text() = 'Character Deaths']/ancestor::table[1]//tr[position() > 1]");
  12.         $deaths = array();
  13.  
  14.         foreach ($rows as $row) {
  15.             $date = $row->firstChild->nodeValue;
  16.             $text = $row->lastChild->nodeValue;
  17.  
  18.             preg_match("/(.+) at Level (\\d+) by (.+)\\./", $text, $matches);
  19.  
  20.             $deaths[] = array(
  21.                 "date"      =>  \DateTime::createFromFormat("M d Y, H:i:s T", $date),
  22.                 "level"     =>  $matches[2],
  23.                 "reason"    =>  $matches[3],
  24.             );
  25.         }
  26.  
  27.         return $deaths;
  28.     }

Estoy pensando como evitar que a cierta cantidad de datos no me devuelva el error 403 pero no se me ocurre como.

Mas o menos son unos 1.000 registros los que tiene que recorrer y la idea es que al script no le tome tanto tiempo recoger sus datos.