終於找到解決方案了,這是一個值得慶祝的事情....
原來是因為微信在源碼中加入了防采集代碼<!--headTrap<body></body><head></head><html></html>-->,把文章源碼中的這一段去掉就可以了!
具體代碼如下:
public function getCon(){
header('Content-type: text/html; charset=utf-8');
import('Vendor.QL.QueryList');
$w_url=$_POST['wurl']; //接收到的文章地址
// 測試文章地址
// $w_url='http://mp.weixin.qq.com/s?__biz=MzA5NzQ5OTMxMA==&mid=2650621512&idx=1&sn=2059946e820805c0d62a450aa3af62be&chksm=88960789bfe18e9f47417eb45cd8efe458af9e93fea3e8e4e242ea2376fd3e4c69f5218293cb&scene=0#wechat_redirect';
// echo "<script>alert('".$w_url."');</script>";
$html = file_get_contents($w_url); //獲取文章源碼並保存到參數中
// echo "<script>alert('".$html."');</script>";
$html = str_replace("<!--headTrap<body></body><head></head><html></html>-->", "", $html); //去除微信中的抓取干擾代碼
// die($w_url);
// var_dump($html);
$data = \QueryList::Query($html,array(
//采集規則庫
//'規則名' => array('jQuery選擇器','要采集的屬性'),
'titleTag' => array('title','text'),
// 'title' => array('#activity-name','text'),
'content' => array('body','text'),
// 'image' => array('img','src'),
//微信規則
'contentWx' => array('#js_content','text'),
// 'imageWx' => array('img','data-src'),
// 'conText' => array('.rich_media_content>p','text'),
))->data;
foreach ($data as $k => $v) {
$data[$k]['imageWx'] = $this->cut_str($v['imageWx'],'?',0);
}
//打印結果
// print_r($data);
$this->assign('conD',$data);
$this->display();
}
