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 相关文章推荐
在RedHat系Linux上部署Python的Celery框架的教程
Apr 07 Python
浅谈插入排序算法在Python程序中的实现及简单改进
May 04 Python
Python二叉树的定义及常用遍历算法分析
Nov 24 Python
Python中django学习心得
Dec 06 Python
Python文本特征抽取与向量化算法学习
Dec 22 Python
TensorFlow实现Batch Normalization
Mar 08 Python
python 生成图形验证码的方法示例
Nov 11 Python
python网络爬虫 CrawlSpider使用详解
Sep 27 Python
Python如何读取文件中图片格式
Jan 13 Python
python三引号如何输入
Jul 06 Python
Python爬虫爬取全球疫情数据并存储到mysql数据库的步骤
Mar 29 Python
Python pandas读取CSV文件的注意事项(适合新手)
Jun 20 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
php查找字符串出现次数的方法
2014/12/01 PHP
PHP版QQ互联OAuth示例代码分享
2015/07/05 PHP
php实现无限级分类查询(递归、非递归)
2016/03/10 PHP
PHP生成(支持多模板)二维码海报代码
2018/04/30 PHP
javascript编程起步(第一课)
2007/01/10 Javascript
JavaScript弹簧振子超简洁版 完全符合能量守恒,胡克定理
2009/10/25 Javascript
JSON 教程 json入门学习笔记
2020/09/22 Javascript
Javascript在IE下设置innerHTML时出现未知的运行时错误的解决方法
2011/01/12 Javascript
使用Jquery打造最佳用户体验的登录页面的实现代码
2011/07/08 Javascript
javascript实现鼠标移到Image上方时显示文字效果的方法
2015/08/07 Javascript
cocos2dx骨骼动画Armature源码剖析(三)
2015/09/08 Javascript
浅谈Angular的$q, defer, promise
2016/12/20 Javascript
带你快速理解javascript中的事件模型
2017/08/14 Javascript
webpack+vue2构建vue项目骨架的方法
2018/01/09 Javascript
用POSTMAN发送JSON格式的POST请求示例
2018/09/04 Javascript
详解Ubuntu安装angular-cli遇到的坑
2018/09/08 Javascript
微信小程序地图(map)组件点击(tap)获取经纬度的方法
2019/01/10 Javascript
JQuery判断radio单选框是否选中并获取值的方法
2019/01/17 jQuery
python实现判断数组是否包含指定元素的方法
2015/07/15 Python
python列表使用实现名字管理系统
2019/01/30 Python
python禁用键鼠与提权代码实例
2019/08/16 Python
树莓派3 搭建 django 服务器的实例
2019/08/29 Python
YUV转为jpg图像的实现
2019/12/09 Python
python开发一个解析protobuf文件的简单编译器
2020/11/17 Python
html5 canvas实现圆形时钟代码分享
2013/12/25 HTML / CSS
Html5+JS实现手机摇一摇功能
2015/04/24 HTML / CSS
美国网上订购鲜花:FTD
2016/09/23 全球购物
英国最受欢迎的在线隐形眼镜商店:VisionDirect.co.uk
2018/12/06 全球购物
西安启天科技有限公司网络工程师面试题笔试题
2016/06/12 面试题
2013的个人自我评价
2013/12/26 职场文书
给老婆的婚前保证书
2014/02/01 职场文书
小学语文课后反思精选
2014/04/25 职场文书
环保倡议书范文
2014/05/12 职场文书
2017新年晚会开幕词
2016/03/03 职场文书
导游词之台湾阿里山
2019/10/23 职场文书
golang http使用踩过的坑与填坑指南
2021/04/27 Golang