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实现在windows服务中新建进程的方法
Jun 30 Python
Python正则表达式教程之三:贪婪/非贪婪特性
Mar 02 Python
Python实现的弹球小游戏示例
Aug 01 Python
python按时间排序目录下的文件实现方法
Oct 17 Python
在Python中Dataframe通过print输出多行时显示省略号的实例
Dec 22 Python
python 实现倒排索引的方法
Dec 25 Python
python实现控制台打印的方法
Jan 12 Python
Django使用Channels实现WebSocket的方法
Jul 28 Python
python使用Word2Vec进行情感分析解析
Jul 31 Python
Django怎么在admin后台注册数据库表
Nov 14 Python
用Python爬取英雄联盟的皮肤详细示例
Dec 06 Python
python数字类型和占位符详情
Mar 13 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 !function_exists(&quot;T7FC56270E7A70FA81A5935B72EACBE29&quot;))代码解密
2011/01/07 PHP
一些php技巧与注意事项分析
2011/02/03 PHP
The specified CGI application misbehaved by not returning a complete set of HTTP headers
2011/03/31 PHP
PHP表单提交表单名称含有点号(.)则会被转化为下划线(_)
2011/12/14 PHP
深入php中var_dump方法的使用详解
2013/06/24 PHP
浅析php中抽象类和接口的概念以及区别
2013/06/27 PHP
WAMP环境中扩展oracle函数库(oci)
2015/06/26 PHP
利用PHP如何写APP接口详解
2016/08/23 PHP
Prototype Hash对象 学习
2009/07/19 Javascript
Jquery中删除元素的实现代码
2011/12/29 Javascript
JavaScript初学者建议:不要去管浏览器兼容
2014/02/04 Javascript
NodeJs中的VM模块详解
2015/05/06 NodeJs
javascript无刷新评论实现方法
2015/05/13 Javascript
基于jQuery实现搜索关键字自动匹配功能
2020/03/26 Javascript
js 判断数据类型的几种方法
2017/01/13 Javascript
jqGrid翻页时数据选中丢失问题的解决办法
2017/02/13 Javascript
Vue组件的使用教程详解
2018/01/05 Javascript
angularjs select 赋值 ng-options配置方法
2018/02/28 Javascript
让webpack+vue-cil项目不再自动打开浏览器的方法
2018/09/27 Javascript
WebGL学习教程之Three.js学习笔记(第一篇)
2019/04/25 Javascript
详解如何探测小程序返回到webview页面
2019/05/14 Javascript
[47:43]Alliance vs KG 2019国际邀请赛小组赛 BO2 第一场 8.16
2019/08/18 DOTA
python使用tornado实现登录和登出
2018/07/28 Python
详解如何设置Python环境变量?
2019/05/13 Python
详解Python的循环结构知识点
2019/05/20 Python
python求最大值最小值方法总结
2019/06/25 Python
keras 特征图可视化实例(中间层)
2020/01/24 Python
如何实现更换Jupyter Notebook内核Python版本
2020/05/18 Python
Python暴力破解Mysql数据的示例
2020/11/09 Python
CSS3中的注音对齐属性ruby-align用法指南
2016/07/01 HTML / CSS
css3实现3D色子翻转特效
2014/12/23 HTML / CSS
商务英语毕业生自荐信范文
2013/11/08 职场文书
公司捐款倡议书
2014/05/14 职场文书
国庆节促销广告语2014
2014/09/19 职场文书
社区党的群众路线教育实践活动领导班子对照检查材料
2014/09/25 职场文书
2015初一年级组工作总结
2015/07/24 职场文书