PHP+正则抓取淘宝装修市场设计师数据
2017-05-31 00:00
246 查看
摘要: 意图了解那17451个无线模板都是哪些人做的
https://zxn.taobao.com/wei_template_list.htm?p=1
至
https://zxn.taobao.com/wei_template_list.htm?p=870
取出html源文件
利用正则来解析html
取matches[1]得到设计师的id号
遍历分页迭加得所有的设计id号数组
4.1 先声明一个空数组用来不加的merge用
4.2 然后在循环体中合并数组
4.3 让$page=2验证结果
对数组元素去重复
sizeof()求数组长度
echo '无线设计师人数为:' . sizeof($designer_id_array);
下载地址:https://git.oschina.net/laeser/spider
目的
竞争对手分析,了解淘宝装修市场上线了多少无线模板设计师步骤
找到目标页面https://zxn.taobao.com/wei_template_list.htm?p=1
至
https://zxn.taobao.com/wei_template_list.htm?p=870
取出html源文件
$html = file_get_contents("https://zxn.taobao.com/wei_template_list.htm?p=$i");
利用正则来解析html
$start = "\/\/zxn.taobao.com\/designer_detail\.htm\?designerId="; $end = "\">"; preg_match_all("/$start(\d+)$end/", $html, $matches);
取matches[1]得到设计师的id号
array(20) { [0]=> string(7) "1038354" [1]=> string(7) "1029480" [2]=> string(7) "1036438" [3]=> string(5) "14040" ... [18]=> string(7) "1033337" [19]=> string(5) "75477" }
遍历分页迭加得所有的设计id号数组
4.1 先声明一个空数组用来不加的merge用
$designer_id_array = [];
4.2 然后在循环体中合并数组
for ($i = 1; $i <= $page ; $i++) { $designer_id_array = array_merge($designer_id_array, $matches[1]); }
4.3 让$page=2验证结果
array(40) { [0]=> string(7) "1038354" [1]=> string(7) "1029480" [2]=> string(7) "1036438" [39]=> string(5) "40890" }
对数组元素去重复
array_unique($designer_id_array)
sizeof()求数组长度
echo '无线设计师人数为:' . sizeof($designer_id_array);
大功告成
代码没多讲究,只为实现我自己要的功能。下载地址:https://git.oschina.net/laeser/spider
相关文章推荐
- php使用curl和正则表达式抓取网页数据示例
- 《程序员的第一年》---------- 【抓取网页数据】定时查寻淘宝搜索结果并用excel记录下来(HttpWebRequest与正则等的使用)
- php 正则抓取网页的table数据
- [置顶] PHP之数据采集[抓取阿里巴巴上宁波企业的详细信息] - 非正则实现
- 使用php发送Http请求,抓取网页数据
- java 正则 抓取数据
- php 关于抓取不到数据的问题
- PHP的cURL库功能简介 抓取网页、POST数据及其他
- 使用CodeIgniter来调用淘宝SDK数据进行PHP开发
- 转载:PHP的cURL库功能简介:抓取网页,POST数据及其他
- 如何处理在使用正则表达式抓取数据是栈溢出问题
- c#通用正则解析代码,抓取数据无需再写正则
- PHP抓取淘宝店信誉实例 正则+Snoopy抓取框架
- 使用正则表达式抓取博客园列表数据
- 淘宝评论数据抓取简记
- PHP使用cURL抓取数据
- PHP数据验证常用正则表达收集
- PHP的cURL库功能简介:抓取网页,POST数据及其他