随笔分类 -  Python

Simple but strong!
python实现的邮件自动群发脚本
摘要:很多时候我们可能需要在某种情况下自动发送邮件给对方,标准库的smtplib可以实现这个功能,代码比较简单。#!/usr/bin/env pythonimport smtplibfrom email.mime.text import MIMEText#list of mail address you wana to sendto = ["xx@xx", "xx@xx"]#user and password of your mailMailHost = "smtp.163.com"MailUser = "xxxxxx" 阅读全文

posted @ 2011-03-31 21:14 没钱买域名。。 阅读(1123) 评论(0) 推荐(0)

Python学习笔记之网络爬虫
摘要:网络爬虫的实现可以用BFS(宽度优先搜索),以某个weburl为起始节点,利用标准库的SGMLParser解析html提取超链接,判重后进队,即可实现对网页的抓取。1)用HTMLParser实现的时候编码的问题总是解决不了,很多html解析后都直接抛出异常,试过将当前html的编码格式转成unicode也无法解决。于是改为SGMLParser,便没有出现编码问题,基本上试过很多站点的html都可以正常解析。2)关于url判重,我直接放在一个字典里面然后用has_key()找,可能效率并不高。更高效应该是用hashlib等标准库。感觉代码实现的有点搓,有待优化。。。#!/usr/bin/env 阅读全文

posted @ 2011-03-24 16:11 没钱买域名。。 阅读(1439) 评论(0) 推荐(0)

startswith和endswith
摘要:python文本处理中两个比较简单的函数,大概的用法就是:def main(): s = 'abcd' #start,end表示在串s的起始位置和结束位置,这两个参数是可以缺省的。 #匹配的话返回True,否则返回False start = 0 end = 4 flag = s.startswith('ab', start, end) if flag == True: print 'YES' else: print 'NO' flag = s.endswith('cd', start, end) if flag = 阅读全文

posted @ 2011-03-22 00:08 没钱买域名。。 阅读(335) 评论(0) 推荐(0)

导航