时间:2026-03-01 15:29
人气:
作者:admin
http://data.zz.baidu.com/urls?site=你的域名&token=你的接口密钥import requests def baidu_url_push(url_list, site_domain, token): """ 百度 URL 推送 API 调用函数 :param url_list: 待推送的 URL 列表(如 ["http://www.tqpw.cn/news/4772", ...]) :param site_domain: 验证的站点域名(如 "www.tqpw.cn") :param token: 百度接口调用密钥 :return: 推送结果 """ # 拼接 API 请求地址 api_url = f"http://data.zz.baidu.com/urls?site={site_domain}&token={token}" # 设置请求头,指定内容格式 headers = { "Content-Type": "text/plain", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" } # 将 URL 列表转为每行一个的字符串 url_str = "\n".join(url_list) try: # 发送 POST 请求 response = requests.post(api_url, data=url_str.encode("utf-8"), headers=headers, timeout=10) # 解析返回结果(JSON 格式) result = response.json() return { "status": "success", "data": result, "status_code": response.status_code } except Exception as e: return { "status": "fail", "error": str(e) } # 示例调用 if __name__ == "__main__": # 替换为你的实际信息 MY_SITE = "www.example.com" MY_TOKEN = "你的百度接口密钥" # 待推送的 URL 列表(建议控制在 2000 条以内) push_urls = [ "http://www.tqpw.cn/news/4770", "http://www.tqpw.cn/news/4769", "http://www.tqpw.cn/news/4320" ] # 调用推送函数 push_result = baidu_url_push(push_urls, MY_SITE, MY_TOKEN) print("百度推送结果:", push_result)
{ "remain": 99997, // 今日剩余可推送条数 "success": 3, // 成功推送条数 "failed": 0, // 失败条数 "not_same_site": 0 // 非本站域名的 URL 数量 }
若返回
failed > 0,需检查 URL 是否属于验证的域名、格式是否正确(需带 http/https,结尾无多余字符)。
https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=你的API密钥import requests import json def bing_url_push(url_list, site_id, api_key): """ 必应 URL 推送 API 调用函数 :param url_list: 待推送的 URL 列表 :param site_id: 必应站长工具中的站点 ID(如 "http://www.tqpw.cn/") :param api_key: 必应 API 密钥 :return: 推送结果 """ # 拼接 API 请求地址 api_url = f"https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey={api_key}" # 构造请求体 payload = { "siteUrl": site_id, "urlList": url_list } # 设置请求头 headers = { "Content-Type": "application/json", "User-Agent": "BingWebmasterTools/1.0" } try: # 发送 POST 请求(需将 payload 转为 JSON 字符串) response = requests.post(api_url, data=json.dumps(payload), headers=headers, timeout=15) result = response.json() return { "status": "success", "data": result, "status_code": response.status_code } except Exception as e: return { "status": "fail", "error": str(e) } # 示例调用 if __name__ == "__main__": # 替换为你的实际信息 MY_SITE_ID = "https://www.example.com/" # 必应验证的站点地址(需带 http/https) MY_BING_KEY = "你的必应 API 密钥" push_urls = [ "http://www.tqpw.cn/news/4319", "http://www.tqpw.cn/news/4318" ] # 调用推送函数 push_result = bing_url_push(push_urls, MY_SITE_ID, MY_BING_KEY) print("必应推送结果:", push_result)
{ "d": { "Success": true, "Message": "URL batch submitted successfully." } }
若
Success 为 false,需检查站点 ID 是否正确、API 密钥是否过期、URL 是否属于验证的域名。
sc-domain:example.com 或 https://www.example.com/)。urlNotifications.publishimport json from google.oauth2 import service_account from googleapiclient.discovery import build def google_url_push(url, site_resource_id, key_file_path): """ 谷歌 URL 推送 API 调用函数 :param url: 待推送的单个 URL(谷歌 API 单次推 1 条) :param site_resource_id: GSC 中的资源 ID(如 "sc-domain:example.com") :param key_file_path: 谷歌服务账号密钥文件路径(JSON 格式) :return: 推送结果 """ # 加载服务账号密钥 credentials = service_account.Credentials.from_service_account_file( key_file_path, scopes=["https://www.googleapis.com/auth/webmasters"] ) # 构建 GSC API 客户端 service = build("searchconsole", "v1", credentials=credentials) try: # 构造推送请求体 request_body = { "url": url, "type": "URL_UPDATED" # URL_UPDATED 表示请求重新抓取,URL_SUBMITTED 表示新提交 } # 调用 API 推送 URL response = service.urlNotifications().publish( siteUrl=site_resource_id, body=request_body ).execute() return { "status": "success", "data": response, "url": url } except Exception as e: return { "status": "fail", "error": str(e), "url": url } # 示例调用 if __name__ == "__main__": # 替换为你的实际信息 MY_SITE_RESOURCE = "sc-domain:example.com" # GSC 资源 ID KEY_FILE = "google-service-account-key.json" # 服务账号密钥文件路径 push_url = "http://www.tqpw.cn/news/4775" # 调用推送函数 push_result = google_url_push(push_url, MY_SITE_RESOURCE, KEY_FILE) print("谷歌推送结果:", push_result)
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
{ "urlNotificationMetadata": { "url": "http://www.tqpw.cn/news/4774", "latestUpdate": { "url": "http://www.tqpw.cn/news/4000", "type": "URL_UPDATED", "notifyTime": "2026-03-01T10:00:00.000Z" } } }
http:// 或 https://,且与验证的域名协议一致(如验证的是 HTTPS 站点,推送的 URL 也需是 HTTPS);crontab(Linux)或 任务计划程序(Windows),每日定时推送新生成的 URL;
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳