phpQuery採集微信公衆號文章亂碼

終於找到解決方案了,這是一個值得慶祝的事情....html

原來是由於微信在源碼中加入了防採集代碼<!--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();    }
相關文章
相關標籤/搜索