链接提交,主动推送百度站长平台,自动提交 Url ,shell+php+apache

seo们在工作过程中,经常需要从sitemap里面提取url,提交百度站长平台,那么今天我们就来看看,如何用shell+php+apache 做一个自动url Ping 提交百度站长平台。

shell 部分

前期准备:一个虚拟机,或linux,然后我们来一段优雅的shell。获得sitemap 的url。

第一步,获得sitemap索引文件中,所有的sitemap文件,并保存到1.txt。如下:

curl -s http://www.woshiseo.com/sitemap.xml sleep 1|grep -F -A 1 ‘<loc>’|sed ‘s/<[^<>]*>//g’|sed ‘s/–.*//g’|sed ‘s/2017.*//g’|sed ‘s/^[ \t]*//g’|sed -e ‘/^$/d’>>1.txt;echo ‘is done’;

以上引用部分,将sitemap中的所有sitemap文件,并保存到1.txt中,第一步就ok了。注意:2017这里是sitemap中的lastmod 的时间,如果你是其他时间请自行修改。

第二步,从所有sitemap文件中获取,所有的url。

for i in `cat 1.txt`;do curl -s $i sleep 1|grep -F -A 1 ‘<loc>’|sed ‘s/<[^<>]*>//g’|sed ‘s/–.*//g’|sed ‘s/2017.*//g’|sed ‘s/^[ \t]*//g’|sed -e ‘/^$/d’>>url.txt echo ‘is done’;done;

上文中 1.txt 需要把sitemap的主索引url先获取到。例如:

http://www.woshiseo.com/post/x

http://www.woshiseo.com/post/x1

http://www.woshiseo.com/post/x2

url.txt,就是所有的url地址。

php部分

方法1.新建一个php文件 data-url.php

<?php
$url_data=array(”,);

?>

将url转化成数组格式放入这个php文件中,并命名为 data-url.php

方法2.

<?php

$file = fopen(“url.txt”,”r”);

while(! feof($file))
{
$url_data[]=fgets($file);
}

fclose($file);

?>

提交百度站长平台,下面再新建一个文件ping_url.php,从百度站张平台获得ping提交的php。传送门

<?php
include(‘data-url.php’);
$t=$_GET[‘t’];
$data_size=floor(count($url_data)/2000);
if ($t>$data_size){echo ‘is done! 总共提交了’.count($url_data).’!’;die;}
else{
header(‘Refresh: 10; url=http://localhost:8080/ping_url_p.php?t=’.($_GET[‘t’]+1));
$url_data=array_slice($url_data,$t*2000,2000);
$urls = $url_data;
$api = ‘http://data.zz.baidu.com/urls?site=www.woshiseo.com&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;
}
?>

上文中,网址替换成你的网址,token替换成你的token码。

http://localhost:8080/ping_url.php?t=0

这个是你本地apache的本地文件url,t是数组中每2000条划分一个区间段,求和并取整后的数,比如:总量是14.5万,2000条一次求和取整后大概要74次。这里用程序实现,避免自己换算出问题。

header这个函数,控制页面刷新时间,每隔10秒执行一次刷新,并按t的数值开始+1执行。

 

因此:这个文件开始运行的时候,需要ping_url.php?t=0,从0开始。

 

apache部分

http://localhost:8080/ping_url.php?t=0

当你在本地的apache环境上,开始执行后,你就可以出去抽根烟、倒杯水、跟设计美眉聊会天、尿泡尿啊神吗的,回来发现浏览器页面中出现“is done!总共提交了XXX!”。那就说明执行完了,第二天看下百度站长平台手动提交那里的数值,跟前一天你提交数量是否一致。

好了,这就是把sitemap中url提取出来,本地shell+apache+php文件,读取url.txt循环自动提交百度站长平台的操作过程。作为一个seo,会点程序可以帮你省去很多麻烦,不然的话,哼哼……哼哼哼……… 你就提个需求给你们的技术大牛,然后写文档、过会、评估、立项、开发、测试、上限、你再开始提交站长平台。从起点,你就已经慢了。

三段代码点击查看

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注