爬虫配置项
<?php
header("Content-type:text/html;charset=utf-8");
$url = "http://lockdata.cn/";
$apiUrl = $url . "api/api.php?act=getPhoto&token=3cab7ce4142608c0f40c785b5ab5ca24";
$str = json_decode(file_get_contents($apiUrl), true)["data"];
for ($i = 0; $i < count($str); $i++) {
$user_id = $str[$i]["user_id"];
$user_name = $str[$i]["user_name"];
$user_ticket = $str[$i]["user_ticket"];
$user_photo = $url . $str[$i]["user_photo"];
getImg($user_photo, $user_id, $user_ticket, $i);
}
保存图片到本地
function getImg($url, $user_id, $user_ticket, $i)
{
$state = @file_get_contents($url, 0, null, 0, 1);
if ($state) {
if ($user_ticket == "") {
$filename = 'photo/' . $user_id . '.jpg';
} else {
$filename = 'photo/' . $user_ticket . '.jpg';
}
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$fp2 = @fopen($filename, "a");
fwrite($fp2, $img);
fclose($fp2);
echo $user_ticket . "已保存.....<br>";
} else {
echo $i . "无法获取文件";
}
}
@lockdata.cn
|