python爬虫笔记(1)

  • 对于python爬虫的理解

对于自己感兴趣的页面,或者想要得到的页面资源,通过写一套python爬虫程序,来对页面的html、css、js等文件进行过滤筛选。

  • 对于实现操作的理解(概念性)
  1. 使用库:urllib/urllib2 引用库 构建对象来调用库中request()/ urlopen()等方法
  2. 使用cookie:
  3. 使用正则表达式:

程序段:

捕获异常:

import urllib2

req = urllib2.Request('http://blog.csdn.net/cqcre')
try:
urllib2.urlopen(req)
except urllib2.URLError, e:
if hasattr(e,"code"):
print e.code
if hasattr(e,"reason"):
print e.reason
else:
print "OK"

posted @ 2015-09-24 19:22  周唯一  阅读(121)  评论(0)    收藏  举报