本文介绍如何通过接口盒子提供的免费API提取任意网页内的所有链接并进行智能分类。
提取指定网页内所有链接,并自动归类到以下分类:
参数 | 必填 | 说明 |
---|---|---|
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复制<?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运行复制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"])
&
必须替换为(@)
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。