Linux定时提交网站url到百度站长脚本

发布时间 2023-05-05 14:29:29作者: 神经蛙

以下是一个使用Shell编写的示例脚本,用于在Linux下定时提交URL到百度搜索引擎:

#!/bin/bash

# 要提交的URL列表
urls=(
    'http://www.example.com/page1.html'
    'http://www.example.com/page2.html'
    'http://www.example.com/page3.html'
)

# 百度站长平台API地址
api_url='http://data.zz.baidu.com/urls?site=YOUR_SITE_URL&token=YOUR_TOKEN'

# 循环提交每个URL并记录结果
for url in "${urls[@]}"
do
    # 创建POST请求
    response=$(curl -H "Content-Type: text/plain" --data-binary $url $api_url)

    # 检查请求是否成功
    if [[ $response == *success* ]]
    then
        echo "$url 提交成功 ($response)"
    else
        echo "$url 提交失败 ($response)"
    fi

    # 等待1秒钟(百度建议最小延迟为500毫秒)
    sleep 1
done

要使用此脚本,您需要将要提交的URL列表替换为自己的URL,并将YOUR_SITE_URL和YOUR_TOKEN替换为自己在百度站长平台上注册的网站URL和API密钥。然后,您可以使用cron或其他调度程序安排定时运行该脚本。

关于定时访问可参考 https://www.cnblogs.com/shenjingwa/p/17373969.html 中的使用方法