网站用WellCMS,网站地图是txt格式,www.abc.com/sitemap.txt
文件中的格式如下:
https://www.abc.com/mulu/11
https://www.abc.com/mulu/12
https://www.abc.com/mulu/13
https://www.abc.com/mulu/14
请教,百度API批量提交的php文件怎么获取批量网址?谢谢
<?php
header('Content-Type: text/html; charset=utf-8');
$html = file_get_contents("http://www.abc.com/sitemap.txt");
$regex = '#(.+?)#'; //这个地方不会写。。。。
preg_match_all($regex,$html,$mats);
$urls = $mats[1];
$chunk_result = array_chunk($urls,500);
//百度收录提交
foreach($chunk_result as $k){
$urls=$k;
$api = 'hhttp://data.zz.baidu.com/urls?site=https://www.abc.com&token=百度token';
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("\n", $urls),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo '百度收录提交' . $result . '
';
}
?>