xaiborweb
Dseda
Programador
No recomendado
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
hola estoy programando un bot de scraping en curl
el cual extraído cada season con un for perfectamente asi
pero cuando le aplico curl nuevamente para cada season ya el for no se cumple y solo me muestra la primera season y no las demás,
el código completo para que lo prueben en un php
si alguien ve el error o lo que esta pasando para que que cuando inspecciono cada season no se cumpla el for inicial le agradezco que me lo comente 😉
se agradece cualquier ayuda [MENTION=9679]cicklow[/MENTION] siempre has sido mi héroe programador xd.
el cual extraído cada season con un for perfectamente asi
PHP:
for($s = 0; $s<count($html_season[1]);$s++) {
$season = explode('">',$html_season[1][$s]);
echo $url_season = 'http://bs.to/'.$season[0];
}
PHP:
for($s = 0; $s<count($html_season[1]);$s++) {
$season = explode('">',$html_season[1][$s]);
echo $url_season = 'http://bs.to/'.$season[0];
$ch = curl_init($url_season);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0');
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Accept-Language: en'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $url_title);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$html_season = curl_exec($ch);
curl_close($ch);
preg_match_all("(<td class=\"nowrap\">(.*)</td>)siU", $html_season, $htmlepisode);
echo $htmlepisode[1][0];
}
el código completo para que lo prueben en un php
PHP:
<?php
$url_title = 'https://bs.to/serie/Game-of-Thrones';
$ch = curl_init($url_title);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0');
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Accept-Language: en'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $url_title);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$html_title = curl_exec($ch);
curl_close($ch);
preg_match_all('/<title>(.*?) -/', $html_title, $title);
$titl = explode(' (',$title[1][0]);
$titulo = str_ireplace(' ','+',str_ireplace('/','%2F',str_ireplace('&','%26',str_ireplace("'",'%27',str_ireplace('"','',str_ireplace(':','',str_ireplace('.','',str_ireplace(',','',str_ireplace('!','', ($titl[0]))))))))));
preg_match_all("(<span id=\"years\">(.*)<em>)siU", $html_title, $year);
if (stripos($year[1][0], "20") ){
preg_match_all("(2(.*) -)siU", $year[1][0], $yer);
$año = '2'.$yer[1][0];
}elseif (stripos($year[1][0], "19") ){
preg_match_all("(1(.*) -)siU", $year[1][0], $yer);
$año = '1'.$yer[1][0];
}
//season
preg_match_all("(<li class=\"button\">(.*)class=\"button\")siU", $html_title, $htmlseason);
preg_match_all('/href="(.*?)</', $htmlseason[1][0], $html_season);
for($s = 0; $s<count($html_season[1]);$s++) {
//numero season
$season = explode('">',$html_season[1][$s]);
$ids = str_ireplace('Film(e)','0', ($season[1]));
echo $url_season = 'http://bs.to/'.$season[0];
$ch = curl_init($url_season);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0');
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Accept-Language: en'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $url_season);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$html_season = curl_exec($ch);
curl_close($ch);
preg_match_all("(<td class=\"nowrap\">(.*)</td>)siU", $html_season, $htmlepisode);
echo $htmlepisode[1][0];
}
?>
si alguien ve el error o lo que esta pasando para que que cuando inspecciono cada season no se cumpla el for inicial le agradezco que me lo comente 😉
se agradece cualquier ayuda [MENTION=9679]cicklow[/MENTION] siempre has sido mi héroe programador xd.
Última edición:

