每日分享—php小爬虫分享(仅供参考学习)

<?php
require('phpQuery/phpQuery.php');

function create_guid($namespace = '') {
 
	static $guid = '';
	$uid = uniqid("", true);
	$data = $namespace;
	$data .= $_SERVER['REQUEST_TIME'];//请求开始时的时间戳。
	$data .= $_SERVER['HTTP_USER_AGENT'];//获取用户相关信息,包括用户浏览器、操作系统等信息。
	$data .= $_SERVER['LOCAL_ADDR'];//本地ip
	$data .= $_SERVER['LOCAL_PORT'];//本地端口
	$data .= $_SERVER['REMOTE_ADDR'];//浏览网页的用户ip
	$data .= $_SERVER['REMOTE_PORT'];//服务器端口
	 
	$hash = strtoupper(hash('ripemd128', $uid . $guid . md5($data)));
	$guid = 
	substr($hash, 0, 8) .
	'-' .
	substr($hash, 8, 4) .
	'-' .
	substr($hash, 12, 4) .
	'-' .
	substr($hash, 16, 4) .
	'-' .
	substr($hash, 20, 12);
	return $guid;
}


phpQuery::newDocumentFile("https://xxxxxxxx");

$pq = pq(".list img");

foreach($pq as $key=>$val){
	
	// var_dump($val);
	$imgSrc="https:".(pq($val)->attr("data-original"));
	// 对字符串按.进行分割,然后形成一个数组
	
	// 取图片的后缀名
	
	$strArray =strrpos($imgSrc,'!');
	$aa=substr($imgSrc,0,$strArray);
	
	$strArray = explode(".",$aa);
	$imgSuffix=array_pop($strArray);
	echo "开始下载图片".$aa."<br/>";
	$content=file_get_contents($aa);//file_get_contents() 把整个文件读入一个字符串中,读取里面的内容信息
    file_put_contents("D:/image/".create_guid().".".$imgSuffix,$content);// 将一个字符串写入文件,选择
	sleep(3);
}
  


  //$content=file_get_contents("https://xxxxxxx");
  //file_put_contents("D:/image/aa.jpg",$content);

?>

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值