通过php获取api接口跳转url

通过php获取api接口跳转url

枫
2023-01-22 / 0 评论 / 94 阅读 / 耗时 124ms / 正在检测是否收录...

介绍

这个可以获取api接口跳转的url,
就是获取图链,有些api图片接口返回的是text
返回的是链接,可以直接全部获取到
8SMPK1~L(FZNRWVV_AM%78Q.png

代码

<?php
$url = "baidu.com";//你要抓取的url链接
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"); 
curl_setopt($ch, CURLOPT_HEADER ,0); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,60); 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER,0);
curl_setopt($ch, CURLOPT_USERAGENT,0);
curl_setopt($ch, CURLOPT_FTPPORT,0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);  //是否抓取跳转后的页面
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 跳过证书检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // 不从证书中检查SSL加密算法是否存在
$res = curl_exec($ch);
$info = curl_getinfo($ch);
$retURL = $info['url'];   // 跳转后的 URL 信息
curl_close($ch);
$filename ="test.txt"; //储存的文本位置
$handle =fopen($filename,"a+"); 
$str =fwrite($handle,$retURL);

//以下为换行符号 注释掉不换行
$strlist =fwrite($handle,"\n");
fclose($handle);

//循环刷新
echo ("<script>setTimeout('window.location.reload()', 1);</script>");

?>

效果

%UI@YVDTKHR%K8U80SJ2AZB.png

7

海报

正在生成.....

评论 (0)

取消