前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >手动生成sitemap

手动生成sitemap

作者头像
尾尾部落
发布2018-09-04 14:47:41
1.8K0
发布2018-09-04 14:47:41
举报
文章被收录于专栏:尾尾部落尾尾部落

本来google的插件是很好用的,但无奈我的wordpress主题好像有问题,安装Google XML Sitemaps后,访问sitemap.xml页面会报错:

代码语言:javascript
复制
error on line 2 at column 6: XML declaration allowed only at the start of the document

如果你也有遇到过同样的问题,并且你有好的解决方案,欢迎与我分享~

于是我们利用python手动生成网站的sitemap。 从Github上克隆python-sitemap

代码语言:javascript
复制
git clone https://github.com/c4software/python-sitemap.git
编写shell vim get_sitemap.sh:
代码语言:javascript
复制
# 运行main.py,且输出sitemap.xml放到wordpress根目录下
/usr/bin/python3 /root/python-sitemap/main.py --domain https://weiweiblog.cn --output /var/www/wordpress/sitemap.xml
# 打印时间
echo "new sitemap get! --" + `date`
设置定时任务

crontab -e 添加下面一行

代码语言:javascript
复制
# 每天01:01分更新
1 1 * * * bash /root/python-sitemap/get_sitemap.sh >> /root/python-sitemap/crontab.log 2>&1

这样,就可以每天自动更新网站的sitemap.xml文件了。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 编写shell vim get_sitemap.sh:
  • 设置定时任务
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档