用PHP爬取51job上苏州地区的PHP职位信息

用PHP爬取51job上苏州地区的PHP职位信息

简单的PHP小爬虫。
效果可以看如下链接: 点击打开链接

本Demo用到了'simple_html_demo.php'这个Dom操作类库。

<?php
header('Content-Type: text/html; charset=UTF-8');  
include 'simple_html_dom.php';
   
        $time= date('Y-m-d H:i:s',time());
        echo '<h1 style="margin: 5PX;">用PHP爬取51job上苏州地区的PHP职位信息</h1>
		      爬取时间:<b>'.$time.'</b>。<br>';
	    echo '<br><br><br><br>';
   
        $stime=microtime(true); //开始计时
        $html = file_get_html('http://search.51job.com/list/070300,000000,0000,00,9,99,PHP,2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare=');


 		$pages=$html->find("div[class=p_wp] div[class=p_in] span[class=td]");
 		$page=preg_replace('/[^0-9]/','',$pages[0]); //获取页数
 		$number=0;
 		
        for ($x=1; $x<=$page; $x++) {
		            $html = file_get_html('http://search.51job.com/jobsearch/search_result.php?fromJs=1&jobarea=070300%2C00&district=000000&funtype=0000&industrytype=00&issuedate=9&providesalary=99&keyword=PHP&keywordtype=2&curr_page='.$x.'&lang=c&stype=1&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&lonlat=0%2C0&radius=-1&ord_field=0&list_type=0&fromType=14&dibiaoid=0&confirmdate=9');
			 		$pageinfo=$html->find("div[id=resultList] div[class=el]");
			 		array_shift($pageinfo);//去除第一条不对的信息
			 		foreach ($pageinfo as $key) {
				        $company=$key->find("span[class=t2] a");
				 		$address=$key->find("span[class=t3]");
				 		$money=$key->find("span[class=t4]");
				        echo $company[0];
				        //echo $job[0];
				        echo '  地址:'.$address[0];
				        echo '  薪资:'.$money[0];
				        echo '<br>';
				        $number++;
			        };
		} 


		$etime=microtime(true);//获取程序执行结束的时间
        $total=$etime-$stime;   //计算差值
        
		echo '<span style="position:absolute;top:70px">用时:<b>'.$total.'</b>秒。<br>苏州一共有<b>'.$number.'</b>条PHP职位需求信息。</span>';

		$html->clear();                 
?>
 
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值