前兩天公布了織夢(mèng)熊掌號(hào)新增數(shù)據(jù)API提交工具,很多人來(lái)問(wèn)我歷史數(shù)據(jù)怎么提交,今天就把代碼也放出來(lái),供大家交流學(xué)習(xí)。
本教程是采用php來(lái)提交,這樣可以全自動(dòng)的批量提交網(wǎng)站的url。
首先我們看看熊掌號(hào)官方給出的示例代碼:
$urls = array( 'http://www.example.com/1.html', 'http://www.example.com/2.html',);$api = 'http://data.zz.baidu.com/urls?appid=1596002713017672&token=vsaJJ3BFNUGx9lGH&type=batch';$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;我們只需要把其中的url地址改為變量,還有就是把API接口改成自己的就行。
冬鏡結(jié)合織夢(mèng)的變量修改后的代碼如下:
<?phprequire_once ("include/common.inc.php");require_once "include/arc.partview.class.php";require_once('include/charset.func.php');$year = date("Y");$month = date("m");$day = date("d");$dayBegin = mktime(0,0,0,7,1,2015);$dayEnd = mktime(23,59,59,$month,$day,$year);$query = "SELECT arch.id,types.typedir FROM dede_arctype as types inner join dede_archives as arch on types.id=arch.typeid where pubdate<".$dayEnd." AND pubdate>".$dayBegin."";$urls=""; $dsql->Execute('arch.id,types.typedir',$query);while($row = $dsql->GetArray('arch.id,types.typedir')){ $urls.="http://CUOxin.com".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".","; }$urls=substr($urls,0,-1);$urls = explode(",",$urls);$api = 'http://data.zz.baidu.com/urls?appid=熊掌號(hào)ID&token=密鑰&type=batch';$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;?>以上代碼大家需要修改三個(gè)地方:
1、建站時(shí)間
$dayBegin = mktime(0,0,0,7,1,2015);將上面的時(shí)間改成自己的,其中7代表月份,1代表日期,2015代表年份
2、url地址修改
$urls.="http://CUOxin.com".str_replace將上面的http://CUOxin.com修改為你自己的主網(wǎng)站
3、歷史數(shù)據(jù)API接口
$api = 'http://data.zz.baidu.com/urls?appid=熊掌號(hào)ID&token=密鑰&type=batch';按照上面的文字說(shuō)明修改成自己的
好了今天的教程就到這里
|
新聞熱點(diǎn)
疑難解答
圖片精選