php代码|php抓取网页特定div区块(php抓取网页指定内容)
时间:2021-03-19 19:59:07 阅读:888
PHP
<?php
//取得指定位址的內容,並储存至text
$text=file_get_contents('http://zshao.vip/');
//去除換行及空白字元(序列化內容才需使用)
$text=str_replace(array("\r","\n","\t","\s"), '', $text);
//取出div标签且id為PostContent的內容,並储存至阵列match
preg_match('/<div[^>]*id="PostContent"[^>]*>(.*?) <\/div>/si',$text,$match);
//打印match[0]
print($match[0]);
?>
取得指定网页內的特定div区块(藉由id判断)
获得其他网站指定内容
网友评论