凉风有信,秋月无边
亏我思娇的情绪、好比度日如年
共 5 篇文章

标签:sitemap

动态php生成sitemap地图方法

通过访问动态php文件。把地图生成保存到静态xml文件 <?php for ($i = 1; $i <= 13; $i++) { $content = file_get_contents("https://www.xxx.com/sitemap/baidu?index=$i"); $c = substr_count($content, '<url>'); if ($c > 1) { //创建存放xml的文件夹 $fp = fopen("pc_sitemap/site$i.xml", "w+"); fwrite($fp, $content); fclose($fp); } } for ($i = 0; $i <= 13; $i++) { $content = file_get_contents("https://m.xxx.com/sitemap/baidu?index=$i"); $c = substr_count($content, '<url>'); if ($c > 1) { //创建存放xml的文件夹 $fp = fopen("wap_sitemap/site$i.xml", "w+"); fwrite($fp, $content); fclose($fp); } }  

赞(0)villainvillain技术笔记 阅读(45)去评论

适合任何cms的通过sitemap地图提交百度站长

<?php // 读取网站地图并转换为 PHP 对象 $xml = simplexml_load_file('https://www.1004619.com/sitemap.xml'); $urls = array(''); // 用来存储 URL foreach ($xml->item as $val) { // 把 URL 添加到 $urls array_push($urls, $val->link); } $api = 'http://data.zz.baidu.com/urls?site=www.1004619.com&token=ovuhS57BoN9zn3J2'; // 提交地址 $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); $result = json_decode($result); // 把返回的json字符串转换为php对象 // 是否推送成功 if (isset($result->success)) { // 输出已推送的 URL 数量和网站地图中的 URL 数量 echo '推送完成,已推送的 URL 数量:' . $result->success . '网站地图中的 URL 数量:' . count($xml->url); }else { echo '推送失败,错误代码:' . $result->error; }  

赞(0)villainvillain技术笔记 阅读(39)去评论

sitemap通过mysql数据库生成网站地图Python代码

#coding:utf-8 #python生成sitemap,超过1万条数据自动生成新文件。 #from __future__ import division # import os,datetime import sys import pymysql.cursors reload(sys) sys.setdefaultencoding('utf-8') hosts = '域名/' dir = os.popen('mkdir /data/wwwroot/forwei/www/sitemaps') path = '/data/wwwroot/forwei/www/sitemaps/' paths = 'sitemaps/' lastmod = datetime.date.today() connection = pymysql.connect(host="127.0.0.1",user="用户名",password="密码",db="表名") sql = 'SELECT classpath FROM phome_enewsclass union select ztpath from phome_enewszt union SELECT titleurl FROM phome_ecms_news' try: with connection.cursor() as cursor: cursor.execute(sql) cnm = cursor.fetchall() pan = open('urls.txt',"w") #hu = open('mobile_url.txt',"w") for i in cnm: for item in i: if len(item) > 2: if item[0] == "/" : pan.write("域名/%s\n" % item[1:]) #hu.write("域名/%s\n" % item[1:]) else: if item[0] != "/": pan.write("域名/%s\n" % item) #hu.write("移动端/%s\n" % item) pan.close() #hu.close() cursor.close() finally: connection.close() def add_file(j,f1,hosts,paths): file_name = 'sitemap_%s.xml'%(j) f1.write("\n<sitemap>\n<loc>%s%s%s</loc>\n<lastmod>%s</lastmod>\n<priority>0.8</priority>\n</sitemap>"%(hosts,paths,file_name,lastmod)) f=open("%s%s"%(path,file_name),"w") f.write('<?xml version="1.0" encoding="utf-8"?>\n<urlset>') return f #判断总的URL数 c = 0...

赞(0)villainvillain值得一看 阅读(36)去评论

根据sitemap提交百度站长的php代码

<?php $token='http://data.zz.baidu.com/urls?site=www.xxxxx.com&token=6lvko54336DCLR6e';//去百度获取 $xml_string = file_get_contents("https://www.1004619.com/sitemap.xml");//网站地图 $xml_string = trim($xml_string); $xml_object = simplexml_load_string($xml_string); $array=[]; $i=0; foreach ($xml_object->url as $key=>$value){ //$i=500 代表从地图获取500条连接 默认是从第一条开始 if($i===88){ break; } $array['aa']= get_object_vars($value); $url.=$array['aa']['loc']."\n"; $i++; } $urls=explode("\n",$url); $ch = curl_init(); $options = array( CURLOPT_URL => $token, 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; ?>  

赞(0)villainvillain技术笔记 阅读(45)去评论