[英]Get jsFiddle result iframe source code with php
我有一個jsFiddle,在https://fiddle.jshell.net/DelightedDoD/yu6nekv4/show/light/中過着幸福的生活
如果我導航到view-source:https://fiddle.jshell.net/DelightedDoD/yu6nekv4/show/light/
我可以查看小提琴的完整渲染源代碼。
我需要在php腳本中獲取完整的渲染源代碼。
這是我嘗試過的:
$src = file_get_contents('https://fiddle.jshell.net/DelightedDoD/yu6nekv4/show/light/');
echo '<textarea>'.$src.'</textarea>';
$ch = curl_init('https://fiddle.jshell.net/DelightedDoD/yu6nekv4/show/light/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
echo '<textarea>'.$content.'</textarea>';
在這兩種情況下,我最終得到的是將小提琴的源代碼呈現到iFrame中的頁面的源代碼, 而不是 我的實際小提琴的源代碼。
要查看結果,請訪問http://dodsoftware.com/shared-resources/php/jsfiddle-mobile-bs-frame.php
view-source:
獲得的結果view-source:
使用PHP或至少獲取該值,然后將其發送到我的php腳本中? 您只需要將curl選項中的Referer設置為要加載的頁面:
$url = 'https://fiddle.jshell.net/DelightedDoD/yu6nekv4/show/light/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, $url);
$content = curl_exec($ch);
curl_close($ch);
echo '<textarea>'.$content.'</textarea>';
嘗試:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://fiddle.jshell.net/DelightedDoD/yu6nekv4/show/light/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = 'Connection: keep-alive';
$headers[] = 'Referer: http://fiddle.jshell.net/DelightedDoD/yu6nekv4/show/light/';
$headers[] = 'DNT: 1';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
$headers[] = 'Accept-Language: en-US,en;q=0.8';
$headers[] = 'Cache-Control: max-age=0';
// $headers[] = 'Accept-Encoding: gzip, deflate, sdch';
$headers[] = 'Host: fiddle.jshell.net';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.10 Safari/537.36';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);
echo '<textarea>'.$server_output .'</textarea>';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.