Python写的网络爬虫程序(很简单)
来源:互联网 发布:linux awk脚本 编辑:程序博客网 时间:2024/05/12 08:01
Python写的网络爬虫程序(很简单)
这是我的一位同学传给我的一个小的网页爬虫程序,觉得挺有意思的,和大家分享一下。不过有一点需要注意,要用python2.3,如果用python3.4会有些问题出现。
python程序如下:
import re,urllibstrTxt=""x=1ff=open("wangzhi.txt","r")for line in ff.readlines():f=open(str(x)+".txt","w+")print linen=re.findall(r"<p>(.*?)<\/p>",urllib.urlopen(line).read(),re.M)for i in n:if len(i)!=0:i=i.replace(" ","")i= i.replace("<strong>","") i = i.replace("</strong>","") strTxt = strTxt + i strTxt = re.sub(r"<a href=(.*?)>", r"", strTxt) strTxt=re.sub(r"<a(.*?)>",r"",strTxt) strTxt=re.sub(r"<span>(.*?)</span>",r"", strTxt) strTxt = re.sub(r"<\/[Aa]>", r"", strTxt) #print strTxt f.write(strTxt) strTxt="" f.close x=x+1ff.close()</span>
http://sports.163.com/14/1126/22/AC0TVK4E00052UUC.html
http://sports.163.com/14/1126/22/AC0TGD4700052UUC.html
http://sports.163.com/14/1126/22/AC0TAHNK00052UUC.html
结果分析:
运行程序,有3个输出文件,分别是3个URL地址对应的网页的内容。
0 0
- Python写的网络爬虫程序(很简单)
- Python写的网络爬虫程序
- 简单的Python网络爬虫程序
- python简单网络爬虫程序
- 使用Python写的第一个网络爬虫程序
- linux下用python写简单的爬虫程序
- [python]简单的网络爬虫
- 爬虫程序的简单介绍(Python)
- 简单的Python爬虫程序
- python简单的爬虫程序
- WSWP(用python写网络爬虫)笔记 一:实现简单爬虫
- 一个简单的python网络爬虫程序(下载博客文章)
- Python写的Web spider(网络爬虫)
- python写网络爬虫的环境搭建(windows完整版)
- Python写的网络刷博器爬虫
- python写简单爬虫的五种方法 (转)
- 用Python写一个简单的爬虫
- Python写的一个爬虫程序
- MFC 通信编程 -----下篇
- 第十四周项目二:带姓名的成绩单
- 利用定时器机制实现多线程编程
- 性能调优基础篇之内存测试常识
- 阻塞 与 非阻塞
- Python写的网络爬虫程序(很简单)
- ruby 文件操作
- UVA - 753 A Plug for UNIX (最大流)
- Oracle EBS 预警系统管理(可用于配置工作流发审批邮件)
- 实现微信好友列表
- Android:应用程序(APK)的编译打包过程
- poj3468(A Simple Problem with Integers)线段树实现
- 【图文笔记】初识uGUI(四)
- 05关于两种context的区别