python爬虫笔记(1)
- 对于python爬虫的理解
对于自己感兴趣的页面,或者想要得到的页面资源,通过写一套python爬虫程序,来对页面的html、css、js等文件进行过滤筛选。
- 对于实现操作的理解(概念性)
- 使用库:urllib/urllib2 引用库 构建对象来调用库中request()/ urlopen()等方法
- 使用cookie:
- 使用正则表达式:
程序段:
捕获异常:
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"

浙公网安备 33010602011771号