日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

php采集安裝教程 Python數(shù)據(jù)采集流程

【php采集安裝教程 Python數(shù)據(jù)采集流程】本篇文章給大家?guī)淼膬?nèi)容是關(guān)于php中常用的采集函數(shù)的總結(jié)(附代碼),有一定的參考價(jià)值,有需要的朋友可以參考一下,希望對你有所幫助 。

php采集安裝教程 Python數(shù)據(jù)采集流程


這幾天關(guān)注了一下PHP的采集程序,才發(fā)現(xiàn)用PHP采集內(nèi)容是這么方便,把經(jīng)常用到的采集函數(shù)在這里總結(jié)一下,方便以后使用!
獲取所有鏈接內(nèi)容和地址
function getAllURL($code){
preg_match_all(‘/”‘ ]+)[“|’]?s*[^>]*>([^>]+)/i’,$code,$arr);
return array(‘name’=>$arr[2],’url’=>$arr[1]);
}
獲取所有的圖片地址
function getImgSrc($code){
$reg = “/]*src=https://www.jinnalai.com/fenxiang/”(http://(.+)/(.+).(jpg|gif|bmp|bnp|png))”/isU”;
preg_match_all($reg, $code, $img_array, PREG_PATTERN_ORDER);
return $img_array[1];
}
當(dāng)前的腳本網(wǎng)址
function getSelfURL(){
if(!empty($_SERVER[“REQUEST_URI”])){
$scriptName = $_SERVER[“REQUEST_URI”];
$nowurl = $scriptName;
}else{
$scriptName = $_SERVER[“PHP_SELF”];
if(empty($_SERVER[“QUERY_STRING”])) $nowurl = $scriptName;
else $nowurl = $scriptName.”?”.$_SERVER[“QUERY_STRING”];
}
return $nowurl;
}
把全角數(shù)字轉(zhuǎn)為半角數(shù)字
function getAlabNum($fnum){
$nums = array(“0”,”1”,”2”,”3”,”4”,”5”,”6”,”7”,”8”,”9”);
$fnums = “0123456789”;
for($i=0;$i<=9;$i++) $fnum = str_replace($nums[$i],$fnums[$i],$fnum);
$fnum = ereg_replace(“[^0-9.]|^0{1,}”,””,$fnum);
if($fnum==””) $fnum=0;
return $fnum;
}
php采集安裝教程 Python數(shù)據(jù)采集流程


去除HTML標(biāo)記
function text2Html($txt){
$txt = str_replace(” “,” ”,$txt);
$txt = str_replace(“<“,”<“,$txt);
$txt = str_replace(“>”,”>”,$txt);
$txt = preg_replace(“/[rn]{1,}/isU”,”
rn”,$txt);
return $txt;
}
清除HTML標(biāo)記
function clearHtml($str){
$str = str_replace(‘<‘,'<‘,$str);
$str = str_replace(‘>’,’>’,$str);
return $str;
}
相對路徑轉(zhuǎn)化成絕對路徑
function relative2Absolute($content, $feed_url) {
preg_match(‘/(http|https|ftp):///’, $feed_url, $protocol);
$server_url = preg_replace(“/(http|https|ftp|news):///”, “”, $feed_url);
$server_url = preg_replace(“//.*/”, “”, $server_url);
if ($server_url == ”) {
return $content;
}
if (isset($protocol[0])) {
$new_content = preg_replace(‘/href=https://www.jinnalai.com/fenxiang/”//’, ‘href=”‘.$protocol[0].$server_url.’/’, $content);
$new_content = preg_replace(‘/src=https://www.jinnalai.com/fenxiang/”//’, ‘src=”‘.$protocol[0].$server_url.’/’, $new_content);
} else {
$new_content = $content;
}
return $new_content;
}
獲取指定標(biāo)記中的內(nèi)容
function getTagData($str, $start, $end){
if ( $start == ” || $end == ” ){
return;
}
$str = explode($start, $str);
$str = explode($end, $str[1]);
return $str[0];
}
php采集安裝教程 Python數(shù)據(jù)采集流程


HTML表格的每行轉(zhuǎn)為CSV格式數(shù)組
function getTrArray($table) {
$table = preg_replace(“‘]*?>’si”,’”‘,$table);
$table = str_replace(“”,’”,’,$table);
$table = str_replace(“”,”{tr}”,$table);
//去掉 HTML 標(biāo)記
$table = preg_replace(“‘<[/!]*?[^<>]*?>’si”,””,$table);
//去掉空白字符
$table = preg_replace(“‘([rn])[s]+’”,””,$table);

推薦閱讀