資料載入中

我是 chung

鎖住記憶

  • Chung
  • 0°C
  • 11 年又 33 天

PHP網路爬蟲之抓取meta value

最近在研究著如何抓取網頁中的meta值...

php中的get_meta_tags函式可以抓取meta name 範例如下...

$tags = get_meta_tags('http://www.example.com/');
echo $tags['author']; // name
echo $tags['keywords']; // php documentation
echo $tags['description']; // a php manual
echo $tags['generator']; // 49.33;-86.59

但無法抓取 open graph 接著找到另一個範例寫著

$sites_html = file_get_contents('http://www.example.com/');

$html = new DOMDocument();
@$html->loadHTML($sites_html);
$meta_og_img = null;
$meta_og_title = null;
//Get all meta tags and loop through them.
foreach($html->getElementsByTagName('meta') as $meta) {
//If the property attribute of the meta tag is og:image
if($meta->getAttribute('property')=='og:image'){
//Assign the value from content attribute to $meta_og_img
$meta_og_img = $meta->getAttribute('content');
}
if($meta->getAttribute('property')=='og:title'){
//Assign the value from content attribute to $meta_og_title
$meta_og_title = $meta->getAttribute('content');
}
}
echo '<img src=' . $meta_og_img . ' /> <br/>';
echo $meta_og_title ;

但目前仍無法得到想要的結果...怪....

研究中....

https://innstory.com/story-PHP網路爬蟲之抓取metavalue-194

上一篇
 石頭是台東的字是我寫的

下一篇
PHP網路爬蟲之抓取OpenGraph(OG)Metatags 
  • 2,255
  • 0
  • 0

發表留言

作者簡介

我是chung,網路工作者

主業是網站系統開發建置
副業是做夢、紀錄故事
作品請參考:teme.biz
做夢請參考:innstory.com
聯絡:chung.teme@gmail.com

有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。


推薦閱讀

作者其他相關類別故事

PHP 利用phpmailer 寄信...

PHP 利用phpmaile…

Chung 10 年又 315 天 2.2K

一般來說其實PHP本身已經提供了Mail()函數可以使用,但由於一些令人不愉快的原因...我租用的V...

Google map 功能導入

Google map 功能導…

Chung 10 年又 239 天 2.6K

寫故事還是得有地圖才好厚! 前幾天,sam同我說有一個客戶有Google map的需求...我其...

PHP 如何檢測陣列是否有重複值

PHP 如何檢測陣列是否有重…

Chung 8 年又 57 天 2.7K

PHP陣列,是在coding時常用到的儲存資料的方式。 但,若陣列中的資料重複,在寫入資料庫時或...