'''
Created on Apr 23, 2010
@author: Leyond
'''
import urllib
from BeautifulSoup import BeautifulSoup
import re
def saveToFile(dir, htmlContent, title,url=""):
nFail = 0
dir +="/%s" % (url)
#print dir
while nFail < 1:
try:
myfile = open(dir, 'w')
myfile.write("<html><head><title>"+str(title)+"</title></head><body>"+str(htmlContent)+"</body></html>")
myfile.close()
return
except:
nFail += 1
print "%s download Fail." % (title)
def findNextBlogHtml(user,htmlContent):
urls = re.findall(r"var.*pre.*?/blog/item/.*?html",htmlContent,re.I)
if(len(urls)==1):
blogUrl = re.findall(r"/blog/item/\w*.html",urls[0],re.I)
print blogUrl[0]
if(len(blogUrl[0])>17):
htmlAddr = blogUrl[0][11:]
#print htmlAddr
else:
htmlAddr ="None"
else:
htmlAddr ="None"
return htmlAddr
def getBlogContentAndTitle(user,htmlUrl):
blogUrl="http://hi.baidu.com/" + user+"/blog/item/"+htmlUrl
sock = urllib.urlopen(blogUrl)
blogHtmlContent = sock.read()
sock.close()
htmlContent = unicode(blogHtmlContent,'gb2312','ignore').encode('utf-8','ignore')
# parser the html content
htmlsoup = BeautifulSoup(htmlContent)
blogContentBlock = htmlsoup.findAll("div",{"id":"m_blog"})
blogContentBlockZero = blogContentBlock[0].findAll("table",{"style":"table-layout:fixed;width:100%"})
#get the title
blogTitleZero = blogContentBlock[0].findAll("div",{"class":"tit"})
blogTitle = blogTitleZero[0].string
#get blog publish date
blogPublishDate = blogContentBlock[0].findAll("div",{"class":"date"})
blogDate = blogPublishDate[0].string
blogData =str("<B>"+blogDate+"</B>") + str(blogContentBlockZero[0])
return blogData,blogTitle,htmlContent
def backUpBlog(user,firstBlogUrl ):
#first read first blog's title and content
blogContent, blogTitle,htmlContent = getBlogContentAndTitle(user,firstBlogUrl)
#save the html to file
saveToFile(user,blogContent,blogTitle,firstBlogUrl)
#find next url
firstBlogUrl = findNextBlogHtml(user,htmlContent)
if firstBlogUrl != "None" :
backUpBlog(user,firstBlogUrl)
else:
print "Backup Finished"
backUpBlog(user="wbweast",firstBlogUrl= "235bf024035c721b8b82a1c6.html")
使用方法跟第一篇相同:
用之前,需要在文件所在目录新建一个目录,例如我的博客就是
codedeveloper,使用这段程序,需要更改两个参数:
其中user那里指的是你的用户名,firstBlogUrl说的是你最
新那篇博文的地址~
有个问题:如何支持中文目录呢?
分享到:
相关推荐
2. **备份原有环境**:如果之前已经安装过其他版本的Python,建议先备份原有的开发环境配置文件,避免后续出现冲突。 #### 具体步骤 1. **双击运行安装程序**:找到已下载的“python-3.7.3-amd64.exe”文件并双击...
Python3是Python语言的第三个主要版本,它对前一个版本Python2进行了大量的改进和优化。Python3支持多种编程范式,包括面向对象、命令式、函数式和过程式编程。在编写看图猜成语程序时,Python3的一些关键特性可能被...
1. **下载安装包**:通过提供的百度网盘链接下载“pythonamd64python-3.7.8-amd64.exe”安装文件。 2. **运行安装程序**:双击下载好的安装文件,启动安装向导。 3. **自定义安装路径**:默认情况下,安装程序会将...
2. **Python 3.6**:Python 3.6是Python编程语言的一个版本,引入了许多新特性,如f-string(格式化字符串字面量)、异步IO的改进、新的类型注解等。这个压缩包可能包含特定于这个版本的Python开发环境设置。 3. **...
1. **数据读取**:GDAL支持众多地理空间数据格式,如TIFF、JPEG、GIF、BMP、PNG等常见图像格式,以及如ESRI Shapefile、GeoJSON、KML、PostGIS数据库等矢量数据格式。这使得GDAL成为处理和分析地理空间数据的强大...
3. **Erasure Coding**:为提高数据冗余和恢复效率,Hadoop 3.0.0引入了Erasure Coding,这是一种更节省空间的备份策略,相对于传统的三副本方式,它能以更低的成本提供相同的数据容错能力。 4. **新数据类型和API*...
1. **InnoDB存储引擎增强**:提升了InnoDB的性能,支持更大的表空间和行记录,增强了ACID合规性和事务处理能力。 2. **JSON支持**:引入了对JSON数据类型的原生支持,方便处理半结构化数据。 3. **性能优化**:包括...
- **数据备份**:定期备份Zookeeper的数据目录,以防数据丢失。 - **监控与报警**:设置合理的监控阈值,及时发现并处理异常情况。 总结,Zookeeper 3.4.13是分布式系统中不可或缺的工具,其强大的功能和稳定的...