很喜欢韩寒的ONE·一个,喜欢每天的一幅图和一句话,所以制作了这个简单API,戳这里!
如果希望得到PC端的客户端,请猛戳这里~这是用VB写出来的一个简单的客户端小程序。
如果你希望在你的站点中引入它们,那么,这个API可能会适合你。
ONE API
数据获取
调用举例 – JavaScript + HTML
脚本地址(SSL):https://blog.mayuko.cn/api/one-api
图片地址(SSL):https://blog.mayuko.cn/api/one-api/img.php
实例:
请求:https://blog.mayuko.cn/api/one-api
返回:
使用方法:
该脚本实质为document.write的脚本。
1.将下面这段代码放入HTML页面的head标签内
<script type="text/javascript" src="https://blog.mayuko.cn/api/one-api"></script>
2.获得图片数据
<img src="https://blog.mayuko.cn/api/one-api/img.php" alt="" />
3.获得标题、内容:
标题:<div id="onetitle"><script>onetitle()</script></div>
图片标题:<div id="oneimga"><script>oneimga()</script></div>
内容:<div id="oneword"><script>oneword()</script></div>
尽情享受吧~
Version 1 - caodan.orgindex.php
<?php //准备对接 header('Content-type: application/x-javascript'); header("Content-type: text/html; charset=uft-8"); //对接完成 //准备接收数据 $url='http://caodan.org';//one一个 $data=get_file($url); //数据接收完成 //准备分析数据 $title='/(?<=(title="Permalink to ))([^<]*)(?=(" rel="bookmark"))/';//匹配标题 $num_1=preg_match_all($title,$data,$match_title); $img='/(?<=(<img src="))([^<]*)(?=(" alt="VOL.))/';//匹配图片 $num_2=preg_match_all($img,$data,$match_img); $img_a='/(?<=(text-align: right;">))([^o]*)(?=(<\/p>))/';//匹配图片标题 $num_3=preg_match_all($img_a,$data,$match_imga); $word='/(?<=(<blockquote><p>))([^<]*)(?=(<\/p><\/blockquote>))/';//匹配文字 $num_4=preg_match_all($word,$data,$match_word); //数据分析完成 //准备处理数据 echo "function oneimg(){document.write(\"" . $match_img[0][0] . "\");}"; echo "function oneimga(){document.write(\"" . $match_imga[0][0] . "\");}"; echo "function onetitle(){document.write(\"" . $match_title[0][0] . "\");}"; echo "function oneword(){document.write(\"" . $match_word[0][0] . "\");}"; //数据处理完成 function get_file($url) { $curl = curl_init(); curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); curl_close($curl); return $data; } //对接成功 ?>
img.php
<?php function get_file($url) { $curl = curl_init(); curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); curl_close($curl); return $data; } //准备收集数据 $url='http://caodan.org';//one一个 $data=get_file($url); $img='/(?<=(<img src="))([^<]*)(?=(" alt="VOL.))/';//匹配图片 $num_2=preg_match_all($img,$data,$match_img); $imgurl=$match_img[0][0]; //准备接收图片 if($imgurl){ header('Content-Type: image/JPEG'); @ob_end_clean(); @readfile($imgurl); @flush(); @ob_flush(); exit(); }else{ exit('error'); } //图片接收完毕 ?>
Version 2 -wufazhuce.com
index.php
<?php //准备对接 header('Content-type: application/x-javascript'); header("Content-type: text/html; charset=utf-8"); //对接完成 //准备接收数据 $url='http://wufazhuce.com';//one一个url $data=get_file($url); //数据接收完成 //准备分析数据 $title='/(?<=(<p class="titulo">))[^<]*(?=(<\/p>))/';//匹配标题 $num_1=preg_match_all($title,$data,$match_title); $imgurl='/(?<=(<img class="fp-one-imagen" src="))[^<]*(?=(" alt="" \/><\/a> ))/';//匹配图片url $num_2=preg_match_all($imgurl,$data,$match_imgurl); $img_title='/(?<=( ))[^>]*(?=(&))/';//匹配图片标题 $num_3=preg_match_all($img_title,$data,$match_imgtitle); $img_author='/(?<=(&))[^<]*(?=(<\/div>))/';//匹配图片作者 $num_4=preg_match_all($img_author,$data,$match_imgauthor); $word='/(?<=(<a href="http:\/\/wufazhuce.com\/one\/)\d{4}">)[^>]*(?=(<))/';//匹配文字 $num_5=preg_match_all($word,$data,$match_word); //数据分析完成 //准备处理数据 echo "function onetitle(){document.write(\"" . $match_title[0][0] . "\");}"; echo "function oneimga(){document.write(\"" . $match_imgtitle[0][0].'<br>'.$match_imgauthor[0][0] . "\");}"; echo "function oneword(){document.write(\"" . $match_word[0][1] . "\");}"; //数据处理完成 function get_file($url) { $curl = curl_init(); curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); curl_close($curl); return $data; } //对接成功 ?>
img.php
<?php function get_file($url) { $curl = curl_init(); curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); curl_close($curl); return $data; } //准备收集数据 $url='http://wufazhuce.com';//one一个url $data=get_file($url); $img='/(?<=(<img class="fp-one-imagen" src="))[^<]*(?=(" alt="" \/><\/a> ))/';//匹配图片 $num_2=preg_match_all($img,$data,$match_img); $imgurl=$match_img[0][0]; //准备接收图片 if($imgurl){ header('Content-Type: image/JPEG'); @ob_end_clean(); @readfile($imgurl); @flush(); @ob_flush(); exit(); }else{ exit('error'); } //图片接收完毕 ?>