前几天我做了非常相似的事情。我选择使用 jQuery、Ajax 和 PHP 来收集页面并将它们分解。我已经包含了我的代码的稀释版本。
对于 PHP,我使用了 CURL (get-url.php):
$requestURL = $_GET['url'];
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $requestURL);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl_handle, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($curl_handle, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl_handle, CURLOPT_MAXREDIRS, 10);
curl_setopt($curl_handle, CURLOPT_DNS_USE_GLOBAL_CACHE, FALSE);
curl_setopt($curl_handle, CURLOPT_FORBID_REUSE, TRUE);
$content = curl_exec($curl_handle);
curl_close($curl_handle);
echo $content;
然后对于 Ajax,我使用了:
var url = /* URL you want to retrieve */;
$.ajax({
url: "get-url.php?url=" + url,
type: "GET",
dataType: "html",
cache: false,
success: function(data, textStatus, jqXHR){
var header = data.find('#header').html();
var footer = data.find('#footer').html();
$(header_DOM).html(header);
$(footer_DOM).html(footer);
}
});
这只是一个指南。改变这个想法以满足您的需求。