php采集web数据

本文以360影视数据为例,介绍如何使用PHP进行网页数据采集。重点讲解了reg_match_all函数在正则表达式全局匹配中的应用,该函数能返回匹配模式的次数,错误时返回FALSE。通过分析网页源代码,提取关键数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以360影视数据采集为例

<?php

		$player ='http://www.360kan.com/dianying/index.html';
		$tvinfo = file_get_contents($player);
	

		$tvzz = '#<div data-block="tj-网络热播" class="g-wrap p-type13" monitor-desc="网络热播" monitor-shortpv>[\s\S]+?<div class="g-wrap" data-block="tj-辣评电影" monitor-desc="辣评电影" monitor-shortpv>#';




		preg_match_all($tvzz, $tvinfo, $tvarr);
		var_dump($tvarr);

其中,reg_match_all  函数用于进行正则表达式全局匹配,成功返回整个模式匹配的次数(可能为零),如果出错返回 FALSE 。

$tv

<div data-block="tj-网络热播" class="g-wrap p-type13" monitor-desc="网络热播" monitor-shortpv>

...

<div class="g-wrap" data-block="tj-辣评电影" monitor-desc="辣评电影" monitor-shortpv>

是为原网页的前后部分

采集到数据

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值