]+)[”|\']?\s*[^]*([^]+)\/a/i',$code,$arr);
return
array('name'=$arr[2],'url'=$arr[1]);
}
//获取指定标记中的内容
function
get_tag_data($str,
$start,
$end)
{
if
(
$start
==
”
||
$end
==
”
)
{
return;
}
$str
=
explode($start,
$str);
$str
=
explode($end,
$str[1]);
return
$str[0];
}
//HTML表格的每行转为CSV格式数组
function
get_tr_array($table)
{
$table
=
preg_replace(”‘td[^]*?'si”,'”‘,$table);
$table
=
str_replace(”/td”,'”,',$table);
$table
=
str_replace(”/tr”,”{tr}”,$table);
//去掉
HTML
标记
$table
=
preg_replace(”‘[\/\!]*?[^]*?'si”,””,$table);
//去掉空白字符
$table
=
preg_replace(”‘([\r\n])[\s]+'”,””,$table);
$table
=
str_replace(”
“,””,$table);
$table
=
str_replace(”
“,””,$table);
$table
=
explode(”,{tr}”,$table);
array_pop($table);
return
$table;
}
//将HTML表格的每行每列转为数组 , 采集表格数据
function
get_td_array($table)
{
$table
=
preg_replace(”‘table[^]*?'si”,””,$table);
$table
=
preg_replace(”‘tr[^]*?'si”,””,$table);
$table
=
preg_replace(”‘td[^]*?'si”,””,$table);
$table
=
str_replace(”/tr”,”{tr}”,$table);
$table
=
str_replace(”/td”,”{td}”,$table);
//去掉
HTML
标记
$table
=
preg_replace(”‘[\/\!]*?[^]*?'si”,””,$table);
//去掉空白字符
$table
=
preg_replace(”‘([\r\n])[\s]+'”,””,$table);
$table
=
str_replace(”
“,””,$table);
$table
=
str_replace(”
“,””,$table);
$table
=
explode('{tr}',
$table);
array_pop($table);
foreach
($table
as
$key=$tr)
{
$td
=
explode('{td}',
$tr);
array_pop($td);
$td_array[]
=
$td;
}
return
$td_array;
}
//返回字符串中的所有单词
$distinct=true
去除重复
function
split_en_str($str,$distinct=true)
{
preg_match_all('/([a-zA-Z]+)/',$str,$match);
if
($distinct
==
true)
{
$match[1]
=
array_unique($match[1]);
}
sort($match[1]);
return
$match[1];
}
怎么用php采集网站数据简单的分了几个步骤:
1、确定采集目标
2、获取目标远程页面内容(curl、file_get_contents)
3、分析页面html源码,正则匹配你需要的内容(preg_match、preg_match_all),这一步最为重要 , 不同页面正则匹配规则不一样
4、入库
php采集数据函数的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于php 采集、php采集数据函数的信息别忘了在本站进行查找喔 。
- redis的热点数据缓存 redis热点数据切换
- redis缓存失效怎么办 redis缓存数据不一致
- mongodb 更新子文档 mongodb数据文件无法新建
- mongodb查看数据库大小 查看mongodb集群容量
- mysql数据统计方案
- mysql创建数据表时指定字符集 mysql有符号创建
- 纯phpmysql
- mysql数据库优化 mysql订单优化
- 查找php.ini phpredis查找
- redis哨兵模式数据不一致 redis为什么叫哨兵
