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小技巧分享
Nov 22 Python
Python合并多个装饰器小技巧
Apr 28 Python
Python sys.argv用法实例
May 28 Python
Python如何实现守护进程的方法示例
Feb 08 Python
Python自动生产表情包
Mar 17 Python
Python 多线程实例详解
Mar 25 Python
python 去除二维数组/二维列表中的重复行方法
Jan 23 Python
一篇文章搞定Python操作文件与目录
Aug 13 Python
如何使用repr调试python程序
Feb 28 Python
Python sklearn中的.fit与.predict的用法说明
Jun 28 Python
python 模拟登录B站的示例代码
Dec 15 Python
两行代码解决Jupyter Notebook中文不能显示的问题
Apr 24 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
介绍几个array库的新函数 php
2006/12/29 PHP
PHP隐形一句话后门,和ThinkPHP框架加密码程序(base64_decode)
2011/11/02 PHP
php并发对MYSQL造成压力的解决方法
2013/02/21 PHP
php文件夹与文件目录操作函数介绍
2013/09/09 PHP
字符串长度函数strlen和mb_strlen的区别示例介绍
2014/09/09 PHP
php 运算符与表达式详细介绍
2016/11/30 PHP
js玩一玩WSH吧
2007/02/23 Javascript
Lab.js初次使用笔记
2015/02/28 Javascript
javascript实现base64 md5 sha1 密码加密
2015/09/09 Javascript
jquery分页插件jquery.pagination.js使用方法解析
2016/04/01 Javascript
原生js封装二级城市下拉列表的实现代码
2016/06/16 Javascript
浅谈js内置对象Math的属性和方法(推荐)
2016/09/19 Javascript
js实现文字无缝向上滚动
2017/02/16 Javascript
vue项目中使用百度地图的方法
2018/06/08 Javascript
对 Vue-Router 进行单元测试的方法
2018/11/05 Javascript
详解React项目如何修改打包地址(编译输出文件地址)
2019/03/21 Javascript
javascript获取元素的计算样式
2019/05/24 Javascript
JavaScript实现简单随机点名器
2019/11/21 Javascript
[03:06]V社市场总监Dota2项目负责人Erik专访:希望更多中国玩家加入DOTA2
2014/07/11 DOTA
新手该如何学python怎么学好python?
2008/10/07 Python
对numpy的array和python中自带的list之间相互转化详解
2018/04/13 Python
Python多线程原理与用法详解
2018/08/20 Python
Python多图片合并PDF的方法
2019/01/03 Python
python读取有密码的zip压缩文件实例
2019/02/08 Python
Python的numpy库下的几个小函数的用法(小结)
2019/07/12 Python
pytorch索引查找 index_select的例子
2019/08/18 Python
python使用Matplotlib改变坐标轴的默认位置
2019/10/18 Python
Python3.6 中的pyinstaller安装和使用教程
2020/03/16 Python
英国床垫在线:Mattress Online
2016/12/07 全球购物
澳大利亚网上买书:Angus & Robertson
2019/07/21 全球购物
物流专业大学的自我评价
2014/01/11 职场文书
2014小学植树节活动总结
2014/03/10 职场文书
保险经纪人求职信
2014/03/11 职场文书
中学生清明节演讲稿
2015/03/18 职场文书
担保贷款承诺书
2015/04/30 职场文书
python基础之类方法和静态方法
2021/10/24 Python