分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

php网络爬虫,实现采集功能

发布时间:2023-09-06 01:41责任编辑:苏小强关键词:爬虫

php实现实时获取当天天气小工具

//获取天气预报网站的网页内容$html = file_get_contents("http://www.weather.com.cn/weather1d/101210101.shtml");//正则表达式$reg = ‘#hour3data.+?\[".+?,.+?,(?<tianqi>.+?),(?<wendu>.+?),#‘;//如果匹配成功,就输出温度相关的信息if(preg_match($reg, $html, $mat)){ ???echo "今天".$mat[‘tianqi‘].",温度".$mat[‘wendu‘];}

根据qq号获取昵称和头像

$url = "http://r.pengyou.com/fcg-bin/cgi_get_portrait.fcg?uins=1579715173";$html = file_get_contents($url);$reg = ‘#.+?\["(.+?)",.+?,.+?,.+?,.+?,.+?,"(.+?)"#‘;if(preg_match($reg, $html, $mat)){ ???//由于防盗链,无法直接使用腾讯的头像链接,所以要先下载到本地 ???file_put_contents("1.jpg",file_get_contents($mat[1])); ???echo "<img src=‘./1.jpg‘ />".$mat[2];}

根据ip获取地址信息

$ip = "14.215.177.38";$html = file_get_contents("http://ip.chinaz.com/".$ip);$regex = ‘#<p class="WhwtdWrap bor-b1s col-gray03">[\s\S]+?<span class="Whwtdhalf w50-0">(.+?)</span>[\s\S]+?</p>#‘;if(preg_match($regex, $html, $mat)){ ???echo $mat[1];}

从起点采集一本指定的小说所有的章节内容,合并到一个txt文件

$html = file_get_contents("http://book.qidian.com/info/1004608738");$regex = ‘#<li data-rid="\d+?"><a href="(.+?)"[\s\S]+?>(.+?)</a>[\s\S]+?</li>#‘;if(preg_match_all($regex, $html, $mats)){ ???foreach($mats[1] as $k => $v){ ???????$html1 = file_get_contents("http:".$v); ???????$regex1 = ‘#<div class="read-content j_readContent">([\s\S]+?)</div>#‘; ???????//匹配内容 ???????if(preg_match($regex1, $html1, $mat)){ ???????????$mat[1] = preg_replace(‘#<.+?>|\s+?#‘, "",$mat[1]); ???????????$content = "\r\n".$mats[2][$k]."\r\n".$mat[1]; ???????????file_put_contents("1.txt", $content, FILE_APPEND); ???????} else { ???????????echo "内容没有匹配成功"; ???????} ???????echo $mats[2][$k]."\n"; ???}}

php网络爬虫,实现采集功能

原文地址:https://www.cnblogs.com/wrpuser/p/8425243.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved