-1
工作我使用這個代碼來獲得一個URL的內容進入: -讓網頁內容不適用於某些鏈接
class MetaTagParser
{
public $metadata;
private $html;
private $url;
public function __construct($url)
{
$this->url=$url;
$this->html= $this->file_get_contents_curl();
$this->set_title();
$this->set_meta_properties();
}
public function file_get_contents_curl()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
public function set_title()
{
$doc = new DOMDocument();
@$doc->loadHTML($this->html);
$nodes = $doc->getElementsByTagName('title');
$this->metadata['title'] = $nodes->item(0)->nodeValue;
}
這個類適用於某些網頁,但對於像這樣的一些網址 - http://www.dnaindia.com/india/report_in-a-first-upa-govt-tweets-the-press_1745346 當我嘗試獲取數據我得到這個錯誤: - 「警告:get_meta_tags(http://www.dnaindia.com/india/report_in-a-first-upa-govt-tweets-the-press_1745346):未能打開流:HTTP請求失敗!HTTP/1.1 403第52行禁止C:\ xampp \ htdocs \ prac \ index.php「
它不工作,爲什麼t他正在發生?
該網站不喜歡你刮。 –
但是當這個鏈接在Facebook上發佈時,它很容易從網頁中提取內容.... – Manish