最简单的python爬虫
来源:互联网 发布:视频去除马赛克软件 编辑:程序博客网 时间:2024/06/05 12:42
姑且称之为爬虫吧,可以从aladd的网站上把400篇文章抓下来,如果页面不存在就报异常,但不会终止抓取。
下一步计划是提取抓取的内容获得有效的信息进行处理,并放入数据库中
# -*- coding: utf-8 -*-__author__ = 'Peng'import string, urllib2from urllib2 import Request, urlopen, URLError, HTTPError#捕获异常后会继续处理def aladd(): for i in range(100, 500): sName = string.zfill(i,5) + '.html'#自动填充成六位的文件名 print '正在下载第' + str(i) + '个网页,并将其存储为' + sName + '......' try: m = urllib2.urlopen('http://aladd.me/' + str(i)+'.htm').read() f = open('D:\\aladd\\'+sName,'w+') #打开一个文件用于读写。如果该文件已存在则将其覆盖。如果该文件不存在,创建新文件。 f.write(m) f.close() except URLError, e: if hasattr(e, 'code'): print 'The server couldn\'t fulfill the request.' print 'Error code: ', e.code elif hasattr(e, 'reason'): print 'We failed to reach a server.' print 'Reason: ', e.reason else: print 'No exception was raised.' # everything is fine#调用aladd()
0 0
- 最简单的python爬虫
- python最简单的爬虫
- 最简单的python 爬虫
- python 3 最简单的小爬虫
- Python 3.0最简单的爬虫
- 最简单的Python网页爬虫
- Python 3.0最简单的爬虫
- python最简单的小爬虫
- python爬虫——写出最简单的网页爬虫
- Python简单的爬虫
- 简单的python爬虫
- 简单的Python 爬虫
- Python网络爬虫4 ---- Linux下编写最简单的scrapy网络爬虫项目
- python 爬虫试手,好简单的爬虫
- PYTHON 爬虫简单的认识
- python简单的爬虫代码
- [python]简单的网络爬虫
- Python实现简单的爬虫
- NLS_INITCAP(x[,y])
- collection详解
- LeetCode | Jump Game
- 设计模式(Javaee)之---监听者模式
- length2
- 最简单的python爬虫
- 2016年7月15日--8月19日(1小时,剩2922小时)
- ViewPager中切换界面Fragment被销毁的问题分析
- INSTRB(C1,C2[,I[,J]])
- win7升级win10后出现VisualSVN Server提供程序无法执行所尝试的操作 0x80041024
- 工厂模式的代码实现,简单易懂。
- INITCAP(c1)
- 自定义Scrollview
- javaee之Struts2练习