python制作最美应用的爬虫


Posted in Python onOctober 28, 2015

安卓最美应用页面爬虫,爬虫很简单,设计的东西到挺多的
文件操作
正则表达式
字符串替换等等

import requests
import re
url = "http://zuimeia.com"
r = requests.get('http://zuimeia.com/community/app/hot/?platform=2')
pattern = re.compile(r'<a class="community-app-cover-wrapper" href="(.*?)" target="_blank">')
urlList = pattern.findall(r.content)

def requestsUrl(url):
 r = requests.get(url)
 title = re.findall(r'"app-title"><h1>(.*?)</h1>',r.content)
 #print title
 category = re.findall(r'<a class="app-tag" href="/community/app/category/title/.*?/?platform=2">(.*?)</a>',r.content)
 #print category

 describe = re.findall(r'<div id="article_content">(.*?)<div class="community-image-wrapper">',r.content)
 #print type(describe[0])
 strdescribe = srtReplace(describe[0])
 #print strdescribe

 downloadUrl = re.findall(r'<a class="download-button direct hidden" href="(.*?)"',r.content)
 #print downloadUrl

 return title,category,strdescribe,downloadUrl

def srtReplace(string):
 listReplace = ['<p>', '<br>', '<h1>', '<h2>', '<h3>', '<h4>', '<h5>', '<h6>', '<h7>','<strong>','</p>', '<br/>', '</h1>', '</h2>', '</h3>', '</h4>', '</h5>',
     '</h6>', '</h7>','</strong>','<b>', '</b>']
 for eachListReplace in listReplace:
  string = string.replace(str(eachListReplace),'\n')

 string = string.replace('\n\n','')
 return string

def categornFinal(category):
 categoryFinal =''
 for eachCategory in category:
  categoryFinal = categoryFinal+str(eachCategory)+'-->'
 return categoryFinal

def urlReplace(url):
 url = url.replace('&', '&')
 return url

requestsUrl("http://zuimeia.com/community/app/27369/?platform=2")
for eachUrl in urlList:
 eachUrl = url+eachUrl
 content = requestsUrl(eachUrl)
 categoryFinal =''

 title = content[0][0]
 category = categornFinal(content[1])
 strdescribe = content[2]
 downloadUrl = urlReplace(content[3][0])

 with open('c:/wqa.txt', 'a+') as fd:
  fd.write('title:'+title+'\n'+'category:'+category+'\n'+'strdescribe:'+strdescribe+'\n'+'downloadUrl:'+downloadUrl+'\n\n\n-----------------------------------------------------------------------------------------------------------------------------\n\n\n')
Python 相关文章推荐
python操作CouchDB的方法
Oct 08 Python
python实现在目录中查找指定文件的方法
Nov 11 Python
python统计日志ip访问数的方法
Jul 06 Python
Python 备份程序代码实现
Mar 06 Python
Python中第三方库Requests库的高级用法详解
Mar 12 Python
Python查找两个有序列表中位数的方法【基于归并算法】
Apr 20 Python
django中模板的html自动转意方法
May 27 Python
PyQt4编程之让状态栏显示信息的方法
Jun 18 Python
通过cmd进入python的实例操作
Jun 26 Python
python发qq消息轰炸虐狗好友思路详解(完整代码)
Feb 15 Python
python GUI库图形界面开发之PyQt5访问系统剪切板QClipboard类详细使用方法与实例
Feb 27 Python
python上传时包含boundary时的解决方法
Apr 08 Python
python使用wmi模块获取windows下的系统信息 监控系统
Oct 27 #Python
详解JavaScript编程中的window与window.screen对象
Oct 26 #Python
深入讲解Python中的迭代器和生成器
Oct 26 #Python
Windows下使Python2.x版本的解释器与3.x共存的方法
Oct 25 #Python
解析Python编程中的包结构
Oct 25 #Python
Python实现获取域名所用服务器的真实IP
Oct 25 #Python
Python制作爬虫采集小说
Oct 25 #Python
You might like
全国FM电台频率大全 - 13 福建省
2020/03/11 无线电
Mysql中limit的用法方法详解与注意事项
2008/04/19 PHP
php页面缓存ob系列函数介绍
2012/10/18 PHP
PHP中类属性与类静态变量的访问方法示例
2016/07/13 PHP
php下载文件,添加响应头的简单实例
2016/09/22 PHP
PHP开发的微信现金红包功能示例
2017/06/29 PHP
PHP实践教程之过滤、验证、转义与密码详解
2017/07/24 PHP
JavaScript格式化日期时间的方法和自定义格式化函数示例
2014/04/04 Javascript
基于JavaScript实现智能右键菜单
2016/03/02 Javascript
js前端面试题及答案整理(一)
2016/08/26 Javascript
教大家轻松制作Bootstrap漂亮表格(table)
2016/12/13 Javascript
jQuery滚动插件scrollable.js用法分析
2017/05/25 jQuery
js实现把时间戳转换为yyyy-MM-dd hh:mm 格式(es6语法)
2017/12/28 Javascript
uploadify插件实现多个图片上传并预览
2019/09/30 Javascript
微信小程序定义和调用全局变量globalData的实现
2019/11/01 Javascript
vue项目里面引用svg文件并给svg里面的元素赋值
2020/08/17 Javascript
Python进程间通信用法实例
2015/06/04 Python
Python扫描IP段查看指定端口是否开放的方法
2015/06/09 Python
Python实现删除文件中含“指定内容”的行示例
2017/06/09 Python
Tensorflow实现卷积神经网络的详细代码
2018/05/24 Python
深入flask之异步非堵塞实现代码示例
2018/07/31 Python
python中字符串内置函数的用法总结
2018/09/13 Python
python实时检测键盘输入函数的示例
2019/07/17 Python
使用python3批量下载rbsp数据的示例代码
2019/12/20 Python
python db类用法说明
2020/07/07 Python
django使用graphql的实例
2020/09/02 Python
巴西最大的体育用品商城:Netshoes巴西
2016/11/29 全球购物
英国最大的女士服装零售商:Bonmarché
2017/08/17 全球购物
高中毕业生自我鉴定例文
2013/12/29 职场文书
《寓言两则》教学反思
2014/02/27 职场文书
学院党的群众路线教育实践活动整改方案
2014/10/04 职场文书
继承公证书格式
2015/01/26 职场文书
卡特教练观后感
2015/06/08 职场文书
学习型家庭事迹材料(2016精选版)
2016/02/29 职场文书
决心书格式及范文
2019/06/24 职场文书
CSS中Single Div 绘图技巧的实现
2021/06/18 HTML / CSS