在PHP中可以使用捲曲:
$link = 'http://example.com/page.html';
$ch = curl_init ($link);
curl_setopt($ch, CURLOPT_AUTOREFERER , true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec ($ch);
curl_close($ch);
echo $data;
希望它能幫助。
編輯
有些網站需要用戶代理:
$useragent= "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0_1 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7A400";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); //add this line
不同者的名單,可以發現here
更新
$data
是HTML頁面的字符串,所以標題:
$string = substr($data, strripos($data,'<title>')+strlen('<title>'));
$string = substr($string, 0, stripos($string, "</title>"));
echo $string;
會給你的頁面標題(如在你的例子)
的Facebook也依賴於特殊meta標籤:
<meta property="og:title" content="Welcome to the homepage" />
<meta property="og:image" content="this-is-the-image-for-this-page.jpg" />
你也可以使用file_get_contents($ url)echo $ url; – Mob
沒錯,但是如果一個網站需要一個useragent,那麼你就被卡住了。 – Sparkup