Ver Mensaje Individual
  #6 (permalink)  
Antiguo 22/06/2017, 12:13
xoceunder
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Respuesta: duda en obtener datos por hora

Código PHP:
Ver original
  1. header('Content-type: application/json');
  2. include('simple_html_dom.php');
  3.  
  4. function doMagic($url)
  5. {
  6.   $curl = curl_init();
  7.  
  8.   $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
  9.   $header[] = "Cache-Control: max-age=0";
  10.   $header[] = "Connection: keep-alive";
  11.   $header[] = "Keep-Alive: 300";
  12.   $header[] = "Set-Cookie: csrftoken=5f078b59b99d5fda680702585019d76c; expires=Sat, 20-Aug-2016 19:24:56 GMT; Max-Age=31449600; Path=/";
  13.   $header[] = "Set-Cookie: REGION=US; Domain=.tv.com; Path=/";
  14.   $header[] = "Set-Cookie: sessionid=e4d968d32106fc8e62811d444a687355; Domain=.tv.com; Path=/";
  15.   $header[] = "Set-Cookie: COUNTRY=US; Domain=.tv.com; Path=/";
  16.   $header[] = 'Cookie: CBS_INTERNAL=0; adblock_status=not_adblocking; AMCVS_10D31225525FF5790A490D4D@AdobeOrg=1; LDCLGFbrowser=e197e176-ebc1-4f96-acb7-42a8bca51623; optimizelyEndUserId=oeu1497187055345r0.2188429643549008; XCLGFbrowser=Cxwh3liAl/Fny2VucQw; hycw4hSBtd=true; JYaH5Y2vxL=true; gebDnVVAmj=6965451112; __gads=ID=452555cf53b8ea98:T=1497187057:S=ALNI_MaGssyIu8k-IGsFYUF1T7AuN1VIBw; AMCV_10D31225525FF5790A490D4D@AdobeOrg=817868104|MCMID|21800541106181592594350749744432666784|MCAAMLH-1497791855|7|MCAAMB-1497791858|NRX38WO0n5BH8Th-nqAG_A|MCCIDH|3162487|MCOPTOUT-1497194255s|NONE|MCAID|2C5B075F051D17DA-600019048000027E; autoplay_video=No; zip=10007; GED_PLAYLIST_ACTIVITY=W3sidSI6IjdLZGEiLCJ0c2wiOjE0OTcxODcxODQsIm52IjoxLCJ1cHQiOjE0OTcxODcwNTQsImx0IjoxNDk3MTg3MTgxfV0.; __utmt=1; s_vnum=1499779055457&vn=2; _tb_sess_r=http://www.tv.com/listings/station/69047006; hId=341768590; _tb_t_ppg=http://www.tv.com/listings/; _ga=GA1.2.974675455.1497187054; _gid=GA1.2.294320983.1497187055; _gat__pm_ga=1; __utma=141309943.974675455.1497187054.1497187054.1497189985.2; __utmb=141309943.5.10.1497189985; __utmc=141309943; __utmz=141309943.1497187054.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); utag_main=v_id:015c974d747400cd3fbad9fcb49005073001b06b00918$_sn:2$_ss:0$_st:1497191925244$_pn:5;exp-session$ses_id:1497189984710;exp-session; pv=9; s_invisit=true; s_getNewRepeat=1497190125415-Repeat; s_lv_undefined=1497190125415; s_lv_undefined_s=Less than 1 day; prevPageType=listings_door; s_cc=true; optimizelySegments={"3040690046":"direct","3041550027":"none","3045900023":"false","3047220031":"gc"}; optimizelyBuckets={}; aam_uuid=21680800803301165794339074368185048536; sq4YFvJMK2=0; optimizelyPendingLogEvents=[]; csrftoken=c2856a4fc36f28c9b15e19025189cfab; COUNTRY=US; REGION=US; sessionid=4ba2e45289fcc4bbc0f5eb80fb518d2f; s_sq=cbsitvcomsite%2Ccbsicbsiall=%26c.%26a.%26activitymap.%26page%3Dtvcom%253A%252Flistings%252Fstation%252F69045259%26link%3DSubmit%26region%3DproviderSettingsPanel%26pageIDType%3D1%26.activitymap%26.a%26.c%26pid%3Dtvcom%253A%252Flistings%252Fstation%252F69045259%26pidt%3D1%26oid%3DSubmit%26oidt%3D3%26ot%3DSUBMIT; tv_provider=directv; tv_provider_type=Satellite';
  17.   $header[] = "Accept-Language: es,en-US;q=0.8,en;q=0.6";
  18.   $header[] = "Pragma: ";
  19.  
  20.  
  21.   curl_setopt($curl, CURLOPT_URL, $url);
  22.   curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
  23.   curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  24.   curl_setopt($curl, CURLOPT_REFERER, "http://www.tv.com/listings/");
  25.   curl_setopt($curl, CURLOPT_ENCODING, "gzip,deflate");
  26.   curl_setopt($curl, CURLOPT_AUTOREFERER, true);
  27.   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  28.   curl_setopt($curl, CURLOPT_TIMEOUT, 30);
  29.   curl_setopt($curl, CURLOPT_FOLLOWLOCATION,true);
  30.  
  31.   $html = curl_exec($curl);
  32.   //echo 'Curl error: '. curl_error($curl);
  33.   curl_close($curl);
  34.  
  35.   return $html;
  36. }
  37.  
  38. function epg_channel($canal){
  39. date_default_timezone_set('America/New_York');
  40. $link = "http://www.tv.com/listings/station/".$canal;
  41. $url = doMagic($link);
  42. $html = new simple_html_dom();
  43. $html->load($url);
  44. $i=0;
  45. $time = time();
  46. foreach($html->find('ul.events li.event') as $row) {
  47.    
  48.    if($i >= 5) break;
  49.    if($row->attr['data-start'] < $time)
  50.     $persona[] = array("hora"=>$row->attr['data-start'],"title"=>$row->find('div.title', 0)->plaintext);
  51.  
  52.     $i++;
  53. }
  54.  
  55.   return $persona;
  56. }
  57. $guia = epg_channel("69033814");
  58. $jsondata=json_encode($guia);
  59. $feed = json_decode($jsondata, true);
  60. echo $jsondata;