16
2024
07
23:43:16

如何使用 Curl 通过 INDEXNOW API 批量提交 URL?



推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

通过indexnow api,我们现在可以在 bing 和 yandex 搜索引擎中立即索引页面。我准备了一个像文档中那样的文件(https://www.indexnow.org/documentation),但我不知道用哪个命令从终端运行它。



您可以使用下面示例中的

curl
(如果它仍然有效)。


curl -X POST \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{"host": "example.org", "key":"my-perfect-key", "urlList": ["https://example.org/page1","https://example.org/page2"]}' \
  https://yandex.com/indexnow

不要忘记将密钥文件放在站点的根目录中。


1
投票
curl -i POST \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{    "host": "example.com", 
    "key":"ffb3f16ace204c8eb58efc30b2e2674d", 
    "keyLocation": "https://example.com/indexnow-key.txt",    "urlList": [      "https://example.com/url1",      "https://example.com/url2"]}' \https://www.bing.com/indexnow

确保托管生成的密钥

注意:不必要使用-X或--request,POST已经被推断出来。


0
投票
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
//-- Параметры --//
$dlm = "|~|";  // Псевдо разделитель
$dlmBreack = "\n"; // Разделитель
$dlmCount = "10000";  // Ограничение количества считываемых строк из файла
$txtfile = "url.txt"; // Файл данных содержащий список URL-адресов
$IndexNowKey = "6352b4ae24df467dbffe0adb9438cd28"; // Ключ IndoxNew
$uRoor = "example.com"; // Домен
$uHttps = "https"; // http или https
$uEngine = "www.bing.com";  // Кому передаем данные - yandex.com, www.bing.com или api.indexnow.org
//-- Параметры --//
$uRLS = "".$uHttps."://$uRoor/"; // Конечный Url с протоколом http или https
$txtfile = preg_replace("!^s+!m", "", $txtfile); // Обрезать пробелы в начале строки
$txtfile = preg_replace("![\n\r]+\s*[\n\r]+!", "\r\n", $txtfile); // Удаляем пустые строки
$DoLink = file_get_contents($txtfile);
$Link = explode($dlmBreack, $DoLink, $dlmCount);
 for($in = 0; $in < count($Link); $in++){
$Urls = explode($dlm, $Link[$in]);
$uUrl = $Urls[0]; // Строка со ссылкой
if ($uUrl!=='') { $BLGe[]="$uUrl"; } // Создаем массив ссылок
 }
$data = array('host' => "$uRoor", 'key' => "$IndexNowKey", 'keyLocation' => "".$uRLS."".$IndexNowKey.".txt", 'urlList' =>array_reverse(array_reverse($BLGe)));
$data_string = json_encode($data);
$ch = curl_init("https://$uEngine/indexnow");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json; 
charset=utf-8'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
$res = curl_exec($ch);
$result = curl_exec($ch);
$http_code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$res = json_encode($res, JSON_UNESCAPED_UNICODE);
 if ($http_code == 200) { echo "<div class=\"alert alert-success text-center\" role=\"alert\">Отет запроса -$http_code <b>Подготовлено и успешно отправлено $count URL</b></div><div class=\"alert alert-secondary text-center\" role=\"alert\">сайт - <b>$uHost</b>, запрос - <b>$uEngine</b></div>"; }
 elseif ($http_code == 202) { echo "<div class=\"alert alert-primary text-center\" role=\"alert\">Отет запроса -$http_code <b>Подготовлено и успешно отправлено $count URL, ожидается проверка ключа IndexNow</b></div><div class=\"alert alert-secondary text-center\" role=\"alert\">сайт - <b>$uHost</b>, запрос - <b>$uEngine</b></div>"; }
 elseif ($http_code == 400) { echo "<div class=\"alert alert-danger text-center\" role=\"alert\">Отет запроса -$http_code <b>Неверный запрос. Неверный формат</b></div><div class=\"alert alert-secondary text-center\" role=\"alert\">сайт - <b>$uHost</b>, запрос - <b>$uEngine</b></div>"; }
 elseif ($http_code == 403) { echo "<div class=\"alert alert-danger text-center\" role=\"alert\">Отет запроса -$http_code <b>Запрещено. Недействительный ключ (например, ключ не найден, файл найден, но ключ отсутствует в файле)</b></div><div class=\"alert alert-secondary text-center\" role=\"alert\">сайт - <b>$uHost</b>, запрос - <b>$uEngine</b></div>"; }
 elseif ($http_code == 422) { echo "<div class=\"alert alert-danger text-center\" role=\"alert\">Отет запроса -$http_code <b>Необрабатываемый объект. URL-адреса не принадлежат хосту или ключ не соответствует схеме в протоколе</b></div><div class=\"alert alert-secondary text-center\" role=\"alert\">сайт - <b>$uHost</b>, запрос - <b>$uEngine</b></div>"; }
 elseif ($http_code == 429) { echo "<div class=\"alert alert-danger text-center\" role=\"alert\">Отет запроса -$http_code <b>Слишком много запросов. Расчитывается какпотенциальный спам</b></div><div class=\"alert alert-secondary text-center\" role=\"alert\">сайт - <b>$uHost</b>, запрос - <b>$uEngine</b></div>"; 
}
 else { echo "<div class=\"alert alert-danger text-center\" role=\"alert\">$http_code -<b> Ошибка отправки списка URL</b></div>"; 
?>

0
投票

工作代码。通过使用PDO连接获取所有URL并创建数组,将其传递给curl

$pdo = con();
$pattern = 'us';
$sql = "SELECT * FROM big_data WHERE country = :pattern AND id > 68251  ORDER BY id ASC limit 1000";
$statement = $pdo->prepare($sql);
$statement->execute([':pattern' => $pattern]);
$res = $statement->fetchAll(PDO::FETCH_ASSOC);

foreach($res as $r){ 
    $url = url($r['id'], $r['plink'], $r);
    $BLGe[]= 'https://www.haveinlist.com'.$url;
}


$IndexNowKey = "df71a7e2a26a44d89f1a5b6c8d3bbf99"; 
$uRoor = "www.haveinlist.com"; 
$uHttps = "https"; 
$uEngine = "www.bing.com";  
$uRLS = "".$uHttps."://$uRoor/"; 
$data = array('host' => "$uRoor", 'key' => "$IndexNowKey", 'keyLocation' => "".$uRLS."".$IndexNowKey.".txt", 'urlList' =>array_reverse(array_reverse($BLGe)));

$ch = curl_init("https://$uEngine/indexnow");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json; charset=utf-8'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
$res = curl_exec($ch);
$http_code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$res = json_encode($res, JSON_UNESCAPED_UNICODE);
if ($http_code == 200) { echo "Response -$http_code List URL sent successfully"; }
elseif ($http_code == 202) { echo "Response -$http_code <b>Accepted. received, pending verification of key IndexNow</b>"; }
elseif ($http_code == 400) { echo "Response -$http_code <b>Bad request. Bad format</b>"; }
elseif ($http_code == 403) { echo "Response -$http_code <b>Forbidden. Invalid key (e.g. key not found)</b>"; }
elseif ($http_code == 422) { echo "Response -$http_code <b>Unprocessed object. URLs do not belong to host or key does not match scheme in protocol</b>"; }
elseif ($http_code == 429) { echo "Response -$http_code <b>Too many requests. Counted as potential spam</b>"; }
else { echo "$http_code -<b> Error sending URL list</b>"; }
0
投票

其他答案对我不起作用,这对我有用:

curl -X POST https://api.indexnow.org/IndexNow \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{
    "host": "example.org",    "key": "81635xxxxxxa4ac6b2d709e495xxxxxx",    "keyLocation": "https://example.org/81635xxxxxxa4ac6b2d709e495xxxxxx.txt",    "urlList": [      "https://example.org",      "https://example.org/ur-2",      "https://example.org/url-3"
    ]
  }'


本文链接:https://hqyman.cn/post/7140.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:
打赏





休息一下~~


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

您的IP地址是: