Jack博客

网站meta信息获取 标题 关键词 描述在线获取api代码分享

本api是本地获取,可用于域名一键获取标题、关键词、描述等操作,做导航的小伙伴可以看看,使用格式api地址+?url=查询域名~

代码如下:

<?php
if ($_GET['url']) {
  $site='http://';
  $url=trim($site.$_GET['url']);
  $info=file_get_contents($url);
  header('Content-type:text/json');
function _charset($url){
  $text = file_get_contents($url);
  $mode = '/charset=(.*)\"/iU';
  preg_match($mode,$text,$result);
  return $result[1];
}
$charset = _charset($url);
function _title($url,$charset){
  $text = file_get_contents($url);
  if ($charset == 'gb2312'){
   $text = iconv('gb2312','utf-8',$text);
  }
  $mode = '/<title>(.*)<\/title>/iU';
  preg_match($mode,$text,$result);
  return $result[1];
}
echo '网站标题:'.$title = _title($url,$charset);
echo "\n";
function _keywords($url,$charset){
  $text = file_get_contents($url);
  if ($charset == 'gb2312'){
   $text = iconv('gb2312','utf-8',$text);
  }
  $mode = '/<meta\s+name=\"keywords\"\s+content=\"(.*)\"\s?\/?>/iU';
  preg_match($mode,$text,$result);
  return $result[1];

}
echo '网站关键词:'.$keywords = _keywords($url,$charset);
echo "\n";
function _description($url,$charset){
  $text = file_get_contents($url);
  if ($charset == 'gb2312'){
   $text = iconv('gb2312','utf-8',$text);
  }
  $mode = '/<meta\s+name=\"description\"\s+content=\"(.*)\"\s?\/?>/iU';
  preg_match($mode,$text,$result);
  return $result[1];
}
echo '网站简介:'.$description = _description($url,$charset);
}

小伙伴要是觉得麻烦可以使用爱站云api接口:https://aizhancloud.cn/wiki/wangzhan/meta.php?url=查询域名,如配置出现问题或者配置的小伙伴可以联系爱站云进行付费操作~

本文标签: 一件抓取   一键获取   api接口  

温馨提示:本文是作者 爱站云 的原创文章,转载请注明出处和附带本文链接!

网友点评

本文暂无评论 - 欢迎您

您好,请先 QQ登录 后进行评论,如您已登录账户,请点击 刷新页面 再进行评论!

⎛⎝爱站云⎠⎞

⎛⎝爱站云⎠⎞

AiZhanCloud.Com

爱站云专注ZBLOG建站领域,分享个人所得技术,用心做好个人博客,喜欢的小伙伴就关注我吧!
«    2023年9月    »
123
45678910
11121314151617
18192021222324
252627282930
最新留言
文章归档
标签列表

Powered By Z-BlogPHP Theme By Jack主题

Sitemap | TXT地图 | HTML地图后花园

免责声明:本博客所展示内容均为互联网技术教程分享,如有侵权等违规信息请联系QQ客服进行删除处理,谢谢配合!

切换白天模式 切换夜间模式 白天返回顶部 夜间返回顶部