cnblogs博客迁移到hexo
cnblogs博客备份
备份地址:https://i.cnblogs.com/BlogBackup.aspx?type=1
备份文件为xml格式,打开备份文件,如下所示:
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-</title><link>http://www.cnblogs.com/shijingjing07/</link><description /><language>zh-cn</language><lastBuildDate>Fri, 20 Jan 2017 13:20:14 GMT</lastBuildDate><pubDate>Fri, 20 Jan 2017 13:20:14 GMT</pubDate><ttl>60</ttl><item><title>博客迁移</title><link>http://www.cnblogs.com/shijingjing07/archive/2017/01/16/6290517.html</link><dc:creator>迪米特</dc:creator><author>迪米特</author><pubDate>Mon, 16 Jan 2017 09:44:00 GMT</pubDate><guid>http://www.cnblogs.com/shijingjing07/archive/2017/01/16/6290517.html</guid><description><![CDATA[<p>博客迁移至 <a href="https://shijingjing07.github.io/" target="_blank">https://shijingjing07.github.io/</a></p>]]></description></item><item><title>cookie欺骗</title><link>http://www.cnblogs.com/shijingjing07/archive/2017/01/06/6256622.html</link><dc:creator>迪米特</dc:creator><author>迪米特</author><pubDate>Fri, 06 Jan 2017 07:55:00 GMT</pubDate><guid>http://www.cnblogs.com/shijingjing07/archive/2017/01/06/6256622.html</guid><description><![CDATA[<p>1.什么是cookie欺骗<br />改变cookie的值,发给服务器,就是cookie欺骗。<br />正常情况下,受浏览器的内部cookie机制所限,每个cookie只能被它的原服务器所访问,我们操作不了原服务器。</p> <p>2.cookie使用示例</p> <p>index.html 写入cookie {'username':'zhangsan','psw':'123'}</p> <div class="cnblogs_code"> <pre><span style="color: #0000ff;"><!</span><span style="color: #ff00ff;">DOCTYPE html</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><</span><span style="color: #800000;">html</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><</span><span style="color: #800000;">head</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><</span><span style="color: #800000;">meta </span><span style="color: #ff0000;">http-equiv</span><span style="color: #0000ff;">="Content-Type"</span><span style="color: #ff0000;"> content</span><span style="color: #0000ff;">="text/html; charset=utf-8"</span><span style="color: #0000ff;">/></span> <span style="color: #0000ff;"><</span><span style="color: #800000;">title</span><span style="color: #0000ff;">></</span><span style="color: #800000;">title</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><</span><span style="color: #800000;">meta </span><span style="color: #ff0000;">charset</span><span style="color: #0000ff;">="utf-8"</span> <span style="color: #0000ff;">/></span> <span style="color: #0000ff;"><</span><span style="color: #800000;">script </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="text/javascript"</span><span style="color: #ff0000;"> src</span><span style="color: #0000ff;">="jquery.min.js"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">script</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><</span><span style="color: #800000;">script </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="text/javascript"</span><span style="color: #ff0000;"> src</span><span style="color: #0000ff;">="jquery.cookie.js"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">script</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><</span><span style="color: #800000;">script </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="text/javascript"</span><span style="color: #0000ff;">></span><span style="background-color: #f5f5f5; color: #000000;"> $.cookie(</span><span style="background-color: #f5f5f5; color: #000000;">'</span><span style="background-color: #f5f5f5; color: #000000;">username</span><span style="background-color: #f5f5f5; color: #000000;">'</span><span style="background-color: #f5f5f5; color: #000000;">, </span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">zhangsan</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">); $.cookie(</span><span style="background-color: #f5f5f5; color: #000000;">'</span><span style="background-color: #f5f5f5; color: #000000;">psw</span><span style="background-color: #f5f5f5; color: #000000;">'</span><span style="background-color: #f5f5f5; color: #000000;">, </span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">123</span><span style="background-color: #f5f5f5; color: #000000;">"</span><span style="background-color: #f5f5f5; color: #000000;">); </span><span style="color: #0000ff;"></</span><span style="color: #800000;">script</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></</span><span style="color: #800000;">head</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><</span><span style="color: #800000;">body</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></</span><span style="color: #800000;">body</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></</span><span style="color: #800000;">html</span><span style="color: #0000ff;">></span></pre> </div> <p>运行index.html,通过Chrome F12开发者工具,可以看到cookie信息。</p> <p><img src="http://images2015.cnblogs.com/blog/300946/201701/300946-20170106155059847-848303078.png" alt="" /></p> <p>可以看到cookie要和domain域名对应。每个cookie只能被对应的域名所访问,其他域名无法访问。</p> <p>3.如何进行cookie欺骗</p> <p>修改hosts,将域名(dev.test.com)对应的ip转为自己的ip(121.43.113.200),写在自己的ip下修改cookie,会发现域名对应的cookie更改了。<br />步骤:<br />1)修改host<br />121.43.113.200 dev.test.com<br />2)将index.html放入服务器121.43.113.200<br />3)访问url:dev.test.com/index.html<br />4)查看cookie信息<br /><img src="http://images2015.cnblogs.com/blog/300946/201701/300946-20170106155240675-1380622233.png" alt="" /><br />5)还原host<br />#121.43.113.200 dev.test.com<br />6)访问url:dev.test.com,会发现dev.test.com中的cookie已被修改。</p> <p>4.cookie欺骗防止<br />随机码防止cookie欺骗<br />原理:在服务端生成唯一随机码,每次提交cookie时带上随机码,和服务端的随机码校验。</p>]]></description></item></channel></rss>
将备份文件解析为.mk文件
备份文件中每个item节点,对应一篇文章。
将每个item中的title,pubDate,description解析出来,写入.mk文件。
代码如下所示:
#!/usr/bin/python # -*- coding: UTF-8 -*- import html2text import xml.sax import datetime import sys reload(sys) sys.setdefaultencoding('utf8') class MovieHandler( xml.sax.ContentHandler ): def __init__(self): self.CurrentData = "" self.title = "" self.pubDate = "" self.description = "" # 元素开始事件处理 def startElement(self, tag ,attributes): self.CurrentData = tag if tag=="item": self.title = "" self.pubDate = "" self.description = "" # 元素结束事件处理 def endElement(self, tag): if tag == "item": try: filename=self.title+".md" fo = open("D:\\certs\\"+filename,'a') fo.write( "---\n") fo.write("title: "+self.title+"\n") GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT' writedate=datetime.datetime.strptime(self.pubDate, GMT_FORMAT) fo.write( "date: "+writedate.strftime('%Y-%m-%d %H:%M:%S')+"\n") fo.write( "tags: \n") fo.write( "categories: \n") fo.write( "---\n") writedesc=html2text.html2text(self.description) fo.write(writedesc) fo.close() except Exception as error: print error.message # 内容事件处理 def characters(self, content): if self.CurrentData == "title": self.title = content elif self.CurrentData == "pubDate": self.pubDate = content elif self.CurrentData == "description": self.description += content if ( __name__ == "__main__"): # 创建一个 XMLReader parser = xml.sax.make_parser() # turn off namepsaces parser.setFeature(xml.sax.handler.feature_namespaces, 0) # 重写 ContextHandler Handler = MovieHandler() parser.setContentHandler( Handler ) parser.parse("CNBlogs_BlogBackup_1_201701_201701.xml")
程序执行后,在D:\certs目录下就生成了hexo网站需要的.mk文件。
如下所示:
将生成的.mk文件copy到hexo _posts目录下
D:\hexo\source\_posts
重新生成静态文件
hexo c
hexo g
hexo s
在浏览器中打开 http://localhost:4000/
结果如下: