本文介绍如何通过接口盒子提供的免费API提取任意网页内的所有链接并进行智能分类。
接口核心功能提取指定网页内所有链接,并自动归类到以下分类:
图片(img)视频(video)音乐(music)压缩包(package)文档(document)CSS样式(css)JavaScript(js)HTML文件(html)PHP文件(php)其他链接(other)请求详情参数
必填
说明
id
是
用户中心的数字ID
key
是
用户中心通讯秘钥
url
是
目标网址(含&需替换为(@))
type
否
地域节点:1=国内(默认),2=香港,3=美国
请求地址
https://cn.apihz.cn/api/wangzhan/getres.php
请求方式
GET 或 POST
返回参数字段
说明
code
状态码(200成功/400错误)
msg
错误提示信息
img/video/...
分类链接集合
调用示例PHP调用示例代码语言:javascript代码运行次数:0运行复制php复制
$apiUrl = 'https://cn.apihz.cn/api/wangzhan/getres.php';
$params = [
'id' => '10000000', // 替换为您的实际ID
'key' => 'your_key_here', // 替换为您的实际KEY
'type' => '1', // 国内节点
'url' => 'www.apihz.cn' // 目标网址
];
// 处理特殊字符:& -> (@)
$params['url'] = str_replace('&', '(@)', $params['url']);
// 发送GET请求
$response = file_get_contents($apiUrl . '?' . http_build_query($params));
// 发送POST请求(推荐)
// $ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, $apiUrl);
// curl_setopt($ch, CURLOPT_POST, true);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// $response = curl_exec($ch);
// curl_close($ch);
// 处理结果
$result = json_decode($response, true);
if ($result['code'] == 200) {
echo "图片链接:" . implode("\n", $result['img']);
} else {
echo "错误:" . $result['msg'];
}
?>Python调用示例代码语言:javascript代码运行次数:0运行复制python运行复制import requests
api_url = "https://cn.apihz.cn/api/wangzhan/getres.php"
params = {
"id": "10000000", # 替换为您的实际ID
"key": "your_key_here", # 替换为您的实际KEY
"type": "1", # 国内节点
"url": "www.apihz.cn" # 目标网址
}
# 处理特殊字符:& -> (@)
params["url"] = params["url"].replace("&", "(@)")
# 发送请求(GET/POST均可)
response = requests.post(api_url, data=params) # 或使用 requests.get(api_url, params=params)
# 处理结果
result = response.json()
if result["code"] == 200:
print("CSS链接:", result.get("css", []))
else:
print("错误:", result["msg"])注意事项特殊字符处理:网址中的&必须替换为(@)认证信息:使用接口盒子官网注册获取专属ID/KEY频次限制:公共KEY(88888888)有并发限制,私有KEY无限制结果处理:内部链接需手动添加域名前缀