
php抓取网页标签
php抓取网页标签(php正则抓取特定标签具有特定属性值的get_data)
网站优化 • 优采云 发表了文章 • 0 个评论 • 163 次浏览 • 2021-09-11 13:04
php抓取网页标签(php正则抓取特定标签具有特定属性值的get_data)
学了几天php正则,抓了一些网站数据,发现写正则又每次都重新抓很麻烦,所以想写一个通用的接口,用具体属性值,直接上传代码。
//$html-被搜索的字符串 $tag-被搜索的标签 $attr-被搜索的属性名称 $value-被搜索的属性值
函数 get_tag_data($html,$tag,$attr,$value){
$regex = "/(.*?)/is";
echo $regex。"
";
preg_match_all($regex,$html,$matches,PREG_PATTERN_ORDER);
返回 $matches[1];
}
//返回值为数组中找到的标签内容
下面会给出一个例子
header("Content-type: text/html; charset=utf-8");
$temp ='
';
$result = get_tag_data($temp,"a","class","fc01");
var_dump($result);
输出结果为
array(6) {[0]=> string(6) "Home" [1]=> string(6) "Log" [2]=> string(6) "LOFTER" [3] ]=> string(6)“专辑”[4]=> string(6)“博友”[5]=> string(9)“关于我”}
查看源代码即可查看
数组(6){
[0]=> 查看全部
学了几天php正则,抓了一些网站数据,发现写正则又每次都重新抓很麻烦,所以想写一个通用的接口,用具体属性值,直接上传代码。
//$html-被搜索的字符串 $tag-被搜索的标签 $attr-被搜索的属性名称 $value-被搜索的属性值
函数 get_tag_data($html,$tag,$attr,$value){
$regex = "/(.*?)/is";
echo $regex。"
";
preg_match_all($regex,$html,$matches,PREG_PATTERN_ORDER);
返回 $matches[1];
}
//返回值为数组中找到的标签内容
下面会给出一个例子
header("Content-type: text/html; charset=utf-8");
$temp ='
';
$result = get_tag_data($temp,"a","class","fc01");
var_dump($result);
输出结果为
array(6) {[0]=> string(6) "Home" [1]=> string(6) "Log" [2]=> string(6) "LOFTER" [3] ]=> string(6)“专辑”[4]=> string(6)“博友”[5]=> string(9)“关于我”}
查看源代码即可查看
数组(6){
[0]=> 查看全部
php抓取网页标签(php正则抓取特定标签具有特定属性值的get_data)
学了几天php正则,抓了一些网站数据,发现写正则又每次都重新抓很麻烦,所以想写一个通用的接口,用具体属性值,直接上传代码。
//$html-被搜索的字符串 $tag-被搜索的标签 $attr-被搜索的属性名称 $value-被搜索的属性值
函数 get_tag_data($html,$tag,$attr,$value){
$regex = "/(.*?)/is";
echo $regex。"
";
preg_match_all($regex,$html,$matches,PREG_PATTERN_ORDER);
返回 $matches[1];
}
//返回值为数组中找到的标签内容
下面会给出一个例子
header("Content-type: text/html; charset=utf-8");
$temp ='
';
$result = get_tag_data($temp,"a","class","fc01");
var_dump($result);
输出结果为
array(6) {[0]=> string(6) "Home" [1]=> string(6) "Log" [2]=> string(6) "LOFTER" [3] ]=> string(6)“专辑”[4]=> string(6)“博友”[5]=> string(9)“关于我”}
查看源代码即可查看
数组(6){
[0]=>
php抓取网页标签(php正则抓取特定标签具有特定属性值的get_data)
网站优化 • 优采云 发表了文章 • 0 个评论 • 163 次浏览 • 2021-09-11 13:04
php抓取网页标签(php正则抓取特定标签具有特定属性值的get_data)
学了几天php正则,抓了一些网站数据,发现写正则又每次都重新抓很麻烦,所以想写一个通用的接口,用具体属性值,直接上传代码。
//$html-被搜索的字符串 $tag-被搜索的标签 $attr-被搜索的属性名称 $value-被搜索的属性值
函数 get_tag_data($html,$tag,$attr,$value){
$regex = "/(.*?)/is";
echo $regex。"
";
preg_match_all($regex,$html,$matches,PREG_PATTERN_ORDER);
返回 $matches[1];
}
//返回值为数组中找到的标签内容
下面会给出一个例子
header("Content-type: text/html; charset=utf-8");
$temp ='
';
$result = get_tag_data($temp,"a","class","fc01");
var_dump($result);
输出结果为
array(6) {[0]=> string(6) "Home" [1]=> string(6) "Log" [2]=> string(6) "LOFTER" [3] ]=> string(6)“专辑”[4]=> string(6)“博友”[5]=> string(9)“关于我”}
查看源代码即可查看
数组(6){
[0]=> 查看全部
学了几天php正则,抓了一些网站数据,发现写正则又每次都重新抓很麻烦,所以想写一个通用的接口,用具体属性值,直接上传代码。
//$html-被搜索的字符串 $tag-被搜索的标签 $attr-被搜索的属性名称 $value-被搜索的属性值
函数 get_tag_data($html,$tag,$attr,$value){
$regex = "/(.*?)/is";
echo $regex。"
";
preg_match_all($regex,$html,$matches,PREG_PATTERN_ORDER);
返回 $matches[1];
}
//返回值为数组中找到的标签内容
下面会给出一个例子
header("Content-type: text/html; charset=utf-8");
$temp ='
';
$result = get_tag_data($temp,"a","class","fc01");
var_dump($result);
输出结果为
array(6) {[0]=> string(6) "Home" [1]=> string(6) "Log" [2]=> string(6) "LOFTER" [3] ]=> string(6)“专辑”[4]=> string(6)“博友”[5]=> string(9)“关于我”}
查看源代码即可查看
数组(6){
[0]=> 查看全部
php抓取网页标签(php正则抓取特定标签具有特定属性值的get_data)
学了几天php正则,抓了一些网站数据,发现写正则又每次都重新抓很麻烦,所以想写一个通用的接口,用具体属性值,直接上传代码。
//$html-被搜索的字符串 $tag-被搜索的标签 $attr-被搜索的属性名称 $value-被搜索的属性值
函数 get_tag_data($html,$tag,$attr,$value){
$regex = "/(.*?)/is";
echo $regex。"
";
preg_match_all($regex,$html,$matches,PREG_PATTERN_ORDER);
返回 $matches[1];
}
//返回值为数组中找到的标签内容
下面会给出一个例子
header("Content-type: text/html; charset=utf-8");
$temp ='
';
$result = get_tag_data($temp,"a","class","fc01");
var_dump($result);
输出结果为
array(6) {[0]=> string(6) "Home" [1]=> string(6) "Log" [2]=> string(6) "LOFTER" [3] ]=> string(6)“专辑”[4]=> string(6)“博友”[5]=> string(9)“关于我”}
查看源代码即可查看
数组(6){
[0]=>