2019年2月22日,发现搜狗图床保存图片会存在失效问题,并且对调用做了限制,所以此接口的部分图片地址已失效。
前面一段时间利用Python爬了不少高清壁纸,这次直接利用这些壁纸做个随机接口。
接口地址:https://qzone.work/api/randpic/
说明:目前系统共收录 5000+ 张图片 API最后更新时间:2018-11-18,每天定时爬取脚本还没写完,有空了继续写,图片的收录应该会持续更新。
**Ps:图片均为https,采用搜狗图床,高速访问,小珏博客
接口模板引用别人的,只写了核心随机调用部分。**
emmm......
源码和收录数据就不放出来了,如果实在懒得封装,放出了一个简单的调用接口。
调用接口:https://qzone.work/api/randpic/random.php
源码展示:
<?php
/*
* Author:小珏
* Uptime:2018-10-8,11:36
* 博客地址:https://qzone.work/
* 接口地址:https://qzone.work/api/randpic/
*/
$api = 'https://qzone.work/api/randpic/randpic.php';
$ret = json_decode ( get_curl ( $api, $data ), true );
header ( "Location:" . $ret ['imgurl'] );
function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobaody = 0) {
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, false );
$httpheader [] = "Accept:*/*";
$httpheader [] = "Accept-Encoding:gzip,deflate,sdch";
$httpheader [] = "Accept-Language:zh-CN,zh;q=0.8";
$httpheader [] = "Connection:close";
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $httpheader );
if ($post) {
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post );
}
if ($header) {
curl_setopt ( $ch, CURLOPT_HEADER, true );
}
if ($cookie) {
curl_setopt ( $ch, CURLOPT_COOKIE, $cookie );
}
if ($referer) {
if ($referer == 1) {
curl_setopt ( $ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=' );
} else {
curl_setopt ( $ch, CURLOPT_REFERER, $referer );
}
}
if ($ua) {
curl_setopt ( $ch, CURLOPT_USERAGENT, $ua );
} else {
curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" );
}
if ($nobaody) {
curl_setopt ( $ch, CURLOPT_NOBODY, 1 );
}
curl_setopt ( $ch, CURLOPT_ENCODING, "gzip" );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
$ret = curl_exec ( $ch );
curl_close ( $ch );
return $ret;
}
?>