このコードを使用して、入力された 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;
}
このクラスは一部のページでは機能しますが、このような一部の URL では機能します - 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 C:\xampp\htdocs\prac\index.php の 52 行目で禁止されています"
それは機能していません、なぜこれが起こっているのですか??