Loading...

php笔记---简单的多层网页内容提取

check评论:0 条 remove_red_eye浏览量:379 change_historyTags:杂七杂八
作者 : 阿硕 date_range日期 : 2018-08-20

举例

求手机号177xxxx6832完整号码

以河南驻马店为例,找出相应号段 http://www.bixinshui.com/city/279

177号段

单号段网页内容


开始程序

创建数组
$arr = array('1773965','1776026','1776027','1776025','1776021','1776022','1776023','1774941','1774697','1773964','1773969','1773968','1773966','1773967','1773953','1773948','1773738','1773702','1771919','1771917','1771918','1771916','1770396','1770397','1779655','1779661','1779656','1779657','1779654','1771914','1774044');

通过遍历数组获取所有单号段网页内容

创建CURL操作

$url = "";//目标网页url
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response= curl_exec($ch);
curl_close($ch);
preg_match_all("/<td>\n\d{7}6832<\/td>/",$response, $a);//通过正则提取特定结尾号码
$shuzu=$a[0];

echo "$shuzu[0]";

echo "<br>";


使用foreach

foreach($arr as $value){
}



完整成品

<?php
$arr = array('1773965','1776026','1776027','1776025','1776021','1776022','1776023','1774941','1774697','1773964','1773969','1773968','1773966','1773967','1773953','1773948','1773738','1773702','1771919','1771917','1771918','1771916','1770396','1770397','1779655','1779661','1779656','1779657','1779654','1771914','1774044');
foreach($arr as $value){

$url = "http://www.bixinshui.com/phone/$value";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);



$response= curl_exec($ch);
curl_close($ch);
preg_match_all("/<td>\n\d{7}6832<\/td>/",$response, $a);
$out=$a[0];

echo "$out[0]";

echo "<br>";

}


 

暂无评论

正在回复给  
去登陆?

标签云

文章留名