資料載入中

我是 chung

鎖住記憶

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

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 ;

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

研究中....

  • 抓取網頁中的meta值方法
  • php中get_meta_tags函式使用
  • open graph抓取問題解決
  • 網頁meta資料抓取技巧
  • 研究網頁meta值的挑戰
https://innstory.com/story-PHP網路爬蟲之抓取metavalue-194

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

下一篇
PHP網路爬蟲之抓取OpenGraph(OG)Metatags 

發表留言

  • Lin Ruo-Sui

    抓取網頁的meta值聽起來挺有意思的,但有時候技術上遇到的問題真讓人頭痛。特別是open graph那部分,似乎比一般的meta要複雜很多。研究的過程中,可能會有不少挫折,但找到解決方案的時候又會讓人覺得值得繼續努力。希望你能順利解決這些問題。
    2026-06-11 下午 2 點回覆

作者簡介

我是chung,網路工作者

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

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


推薦閱讀

作者其他相關類別故事

戶外教學到板橋派出所,當一日小警察。

戶外教學到板橋派出所,當一日…

Chung 2 年又 87 天 849

差婆來了。

暑期課後班都在做些甚麼

暑期課後班都在做些甚麼

Chung 2025-07-31 下午 7 點 392

這天,5U從學校帶回來一些精美的作品,這是他在暑期課後班學習到的藍晒圖作品。 多虧了他,我重新查詢...

爸爸的百萬富翁夢兒子幫我實現在媒體上了

爸爸的百萬富翁夢兒子幫我實現…

Chung 2026-05-18 下午 9 點 498

恭喜 5U 迎來人生首座校外文學勳章! 既然是人生第一次投稿被刊登,說甚麼也得稍微紀錄一下成長道路...