codeinphp
Members-
Posts
38 -
Joined
-
Last visited
-
Days Won
1
Everything posted by codeinphp
-
Command Line curl and PHP curl Different results
codeinphp replied to codeinphp's topic in PHP Coding Help
When you execute script does it create a file with information? -
Command Line curl and PHP curl Different results
codeinphp replied to codeinphp's topic in PHP Coding Help
If sessionID is no good then the command line curl should not work since it needs the same cookie, correct? -
Command Line curl and PHP curl Different results
codeinphp replied to codeinphp's topic in PHP Coding Help
If I take out the Content Length I get 200 but empty return, if I leave it in I get 0 code back and empty file. -
Command Line curl and PHP curl Different results
codeinphp replied to codeinphp's topic in PHP Coding Help
When executed now, with var_dump($html) I still get 200 but an empty file. 200string(336) "HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Sun, 31 May 2015 01:54:04 GMT Content-Type: text/html Transfer-Encoding: chunked X-Powered-By: PHP/5.3.3 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Encoding: gzip ‹" Success! -
Command Line curl and PHP curl Different results
codeinphp replied to codeinphp's topic in PHP Coding Help
Ah, didn't even notice, forogt to delete the first one. Thanks. I'll delete one and see if that helps. -
Command Line curl and PHP curl Different results
codeinphp replied to codeinphp's topic in PHP Coding Help
Thanks for looking at this. I got the Content length from the request header. I have tried it with out the content length and with it increased with same result. Code 200 but empty. -
I am attempting to curl a page to extract some data. I can pass the information thru curl from command line and get exactly what is needed. If I create a php file with the same information and execute the php I get a 200 response but the return is empty. I can't seem to figure it out. Here is the the script. <?php $headers = array(); $headers[]= 'Host: www.streamlive.to'; $headers[]= 'Connection: keep-alive'; $headers[]= 'Content-Length: 27'; $headers[]= 'Pragma: no-cache'; $headers[]= 'Cache-Control: no-cache'; $headers[]= 'Accept: */*'; $headers[]= 'Origin: http://www.streamlive.to'; $headers[]= 'X-Requested-With: XMLHttpRequest'; $headers[]= 'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36'; $headers[]= 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8'; $headers[]= 'Referer: http://www.streamlive.to/tv-guide'; $headers[]= 'Accept-Encoding: gzip, deflate'; $headers[]= 'Accept-Language: en-US,en;q=0.8'; $headers[]= 'Cookie: PHPSESSID=f7mqqpgm3beto9a462fn8a2pl3; _gat=1; _ga=GA1.2.1850053691.1432824439'; $ch = curl_init('http://www.streamlive.to/tv-ajax.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); curl_setopt($ch, CURLOPT_HEADER,true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_VERBOSE, true);//0-FALSE 1 TRUE curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode('getchannelsched&id=9')); curl_exec($ch); $html = curl_exec($ch); curl_close($ch); var_dump($html); if (file_put_contents ('data.xml', $html) !== false) { echo 'Success!'; } else { echo 'Failed'; } ?> Here is the command line curl curl -o test.txt "http://www.streamlive.to/tv-ajax.php" -H "Pragma: no-cache" -H "Origin: http://www.streamlive.to" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: en-US,en;q=0.8" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36" -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "Accept: */*" -H "Cache-Control: no-cache" -H "X-Requested-With: XMLHttpRequest" -H "Cookie: PHPSESSID=f7mqqpgm3beto9a462fn8a2pl3; _gat=1; _ga=GA1.2.1850053691.1432824439';" -H "Connection: keep-alive" -H "Referer: http://www.streamlive.to/tv-guide" --data "action=getchannelsched&id=9" --compressed
-
Well, I am using the xml later time. What is going is my php script would run say every hour or so to update programming information. Each time it runs it will over write the existing xml. So when I go to a particular channel it will display the info in the xml for that channel. Either way I have to get all of the channels programs and times together and that's where I am not successful.
-
Here's an example of html. This what should be parsed for A&E.xml <div class="row"> <div class="col th"> <a class="channel_sched_link" href="javascript:void(0)" title="View A&E full schedule" data-channelid="9"> <img src="http://static.ilive.to/images/tv/AE.JPG" width="30" height="20" alt="A&E" />A&E </a> </div> <div class="prog_cols"> <div class="col ts ts_1 prog_907477 ps_0" data-catid="" > <span class="prog_name">Parking Wars</span> <div class="prog_time">May 27, 2015, 7:00 am - 8:00 am</div> <a class="btn_watchlist " href="javascript:void(0)" data-progid="907477">(+) add to watchlist</a> <div class="prog_desc"> An angry mother and daughter confront a booter in Detroit; and an irate Philadelphia citizen says he got a ticket while trying to help his physically disabled son.<br/> <a class="watchnow" href="http://www.streamlive.to/channels/?q=A%26E">Watch Now</a> </div> </div> <div class="col ts ts_3 prog_907478 ps_1" data-catid="" > <span class="prog_name">Dog the Bounty Hunter</span> <div class="prog_time">May 27, 2015, 8:00 am - 10:00 am</div> <a class="btn_watchlist " href="javascript:void(0)" data-progid="907478">(+) add to watchlist</a> <div class="prog_desc"> Dog pursues two fugitives whose drug problems have hurt their families.<br/> <a class="watchnow" href="http://www.streamlive.to/channels/?q=A%26E">Watch Now</a> </div> </div> </div> <a class="watchnow" href="http://www.streamlive.to/channels/?q=A%26E">Watch Now</a> </div>
-
Thank you for the advice, this is something I was looking for. I am new to PHP and was not sure of the best way to accomplish this, thanks again.
-
Thank you, that //End Function was left over from something. I removed it. I can get the script to create a new xml for each channel name (a&e.xml, abc.xml, cbs.xml soforth) but each file had program info for programs for all channels not just the specific one. For example I run the script, all xml files are created. So if I open a&e.xml, I not only have programs for a&e, but for abc, cbs etc. It's not closing and saving the file the specific channel. Thanks again
-
I am attempting to parse an html page and save the results to an XML file. The purpose of the script is to create a program guide for tv. The script first parses the 'img', if found and matches criteria it will then proceed into getting the program name, program time and description. I can get it to do all of this but it saves all the channels into each xml, not just the info for the particular channel. Example, it reads the html, gets the first channel, say A&E, it then parses info for all the channels in the html and saves all the program info to all the xml, so I end up with 25 xml files, all named based on the different channels, but all containing program info for all channels. I suspect I have something wrong in the loop but can't locate. Any help appreciated. The code below leaves out curl to get $html, not really needed for problem. <?php #CREATE DOM PARSER $dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $dom->formatOutput = true; $dom->preserveWhiteSpace = true; $images= $dom->getElementsByTagName('img'); $childprogram = $xpath->query('//span[@class="prog_name"]'); $childtime= $xpath->query('//div[@class="prog_time"]'); $childdescrip= $xpath->query('//div[@class="prog_desc"]'); foreach($images as $img){ $xml = new DOMDocument("1.0"); $root = $xml->createElement("programme"); $book = $xml->createElement("tvprogram"); $icon= $img ->getAttribute('src'); if( preg_match('/\.(jpg|jpeg|gif)(?:[\?\#].*)?$/i', $icon) ) { //only matching types $channel= $img ->getAttribute('alt'); foreach ($childprogram as $programname) { foreach ($childtime as $programtime) { foreach ($childdescrip as $descrip) { $xml->appendChild($root); $title = $xml->createElement("Channel"); //CHANNEL NAME $showname= $xml->createElement("programname"); //PROGRAM NAME $showtime= $xml->createElement("programtime"); //PROGRAM TIME $descriptime= $xml->createElement("description"); //PROGRAM DESCRIPTION $titleText = $xml->createTextNode($channel); $shownameText= $xml->createTextNode($programname->nodeValue); $showtimeText= $xml->createTextNode($programtime->nodeValue); $showdescripText= $xml->createTextNode($descrip->nodeValue); $title->appendChild($titleText); $showname->appendChild($shownameText); $showtime->appendChild($showtimeText); $descriptime->appendChild($showdescripText); $book->appendChild($title); $book->appendChild($showname); $book->appendChild($showtime); $book->appendChild($descriptime); } } } $root->appendChild($book); }//END OF LOOP $xml->formatOutput = true; $xml->save(dirname(__FILE__)."/streamguideXML/".$channel.".xml") or die("Error"); } //END OF FUNCTION ?>
-
Having some issues with appending an XML file thru a foreach loop. First some info on the script. The script opens an XML file on my server and reads thru the contents extracting url values. It takes that url value (stored in $urlhtml) and passes to a curl function which in turn curls the url, parse information and passes that thru variable $html back to script. The value of $html is then appended to the XML in a particular location. The initial curl ($urlhtml) is a website with TV shows and the $urlhtml represents a particular show. The $html value represents each episode returned from the curl, which needs to be stored under the show being curled. Following an example of the xml sturcture and below that is the script that does this. What is happening is that the url of the is taken from the XML, the foreach loop is entered, the curl is made and the url for each episode is extracted and appended into the xml, but the problem is that instead of the episode url being appended under respective item element in the xml(where the show is located), all the urls for all episodes are appended under the first item in the XML file. So after executing, if I look at the xml file, all of my shows are under a different item element as needed, but all episode titles and episode urls for all shows are located under one item element, not under it's respective show. Any help or advice in getting episodes under it's show would be greatly appreciated. Thanks <feed> <item> <showname>Name of Show Goes Here</showname> <streamUrl>http://locationofshowstream.com</streamUrl> <episodetitle>Name of Episode Goes Here</episodetitle> <episodeurl>URL of the Episode Goes Here</episodeurl> </item> </feed> $xml = new SimpleXMLElement(file_get_contents($xmllocation)); if (!$xml){ echo 'ERROR WHILE PARSING DOCUMENT'; } else{ foreach($xml->item as $item){ $url=$item->streamUrl; if (!$url){ echo 'ERROR WHILE PARSING'; }else{ $html = file_get_html($url); $xmlappend=simplexml_load_file($xmllocation); $elements=$html->find('a[class=main-tt]'); foreach($elements as $element) { $stitle=$element->title; $streamer=$element->href; $urlhtml=curlurl2($streamer); //CURL EACH $episodeurl=substr($urlhtml,2); //CREATES THE FULL URL PATH $epitem= $xmlappend->item; $episodetitle=$xmlappend->item->addChild('eptitle', $stitle); $episode=$xmlappend->item->addchild('epiurl', $episodeurl); } $xmlappend->asXML($xmlsave); } } }