福州網(wǎng)站建設(shè)>網(wǎng)站新聞>php技術(shù)

        php采集微信公眾號(hào)文章源代碼 可用 2022 2023

        發(fā)布日期:2022-12-16瀏覽次數(shù):555 來源:福州網(wǎng)站建設(shè)

        $url="https://mp.weixin.qq.com/s/DYB2ApEjsE8TYPsSOA4DEw";
        
        $html_content= file_get_contents($url);
        
        preg_match('/"js_content" style="visibility: hidden;"-->([\s\S]*?)<\/div/',$html_content,$m);
        
        $content=$m[1];
        //獲取圖片存到本地
         preg_match_all('/data-src="([\s\S]*?)" data-ke-src="([\s\S]*?)"/',$content,$a);
        
         foreach ($a[1] as $key => $value) {
         	 $img_url=set_img($value);
         	 $content = str_replace($value, $img_url, $content); 
         	  $content = str_replace("data-src", "src", $content); 
         }
         echo $content;
        
        
        /**
         * [set_img description]
         * @Author   huangxiaojian(www.txwhj.cn)
         * @DateTime 2022-12-16T19:25:31+0800
         * @param    [type]                   $url [description]
         */
        function set_img($url){
        	$ext = ".png";   //獲取圖片格式
        	$img = file_get_contents($url); 		   
        	 $img_name="upload/cai/".getMillisecond().$ext;
        
        	file_put_contents("../".$img_name,$img); 
        		return "/".$img_name;
        	}
        function getMillisecond() { 
        	list($s1, $s2) = explode(' ', microtime()); 
        	return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000); 
        } 
        
        
        

        以上是由福州網(wǎng)站建設(shè)的小編為你分享了"php采集微信公眾號(hào)文章源代碼 可用 2022 2023"文章,如果你在這方面有什么問題,隨時(shí)聯(lián)系我們

        php技術(shù)有關(guān)的文章
        如果您有什么問題,歡迎咨詢我們客服! 點(diǎn)擊QQ咨詢