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操作日期和时间的方法
Mar 11 Python
11月编程语言排行榜 Python逆袭C#上升到第4
Nov 15 Python
Python+OpenCV人脸检测原理及示例详解
Oct 19 Python
celery4+django2定时任务的实现代码
Dec 23 Python
numpy.random模块用法总结
May 27 Python
Python爬虫图片懒加载技术 selenium和PhantomJS解析
Sep 18 Python
Python实现从N个数中找到最大的K个数
Apr 02 Python
Python3批量创建Crowd用户并分配组
May 20 Python
keras处理欠拟合和过拟合的实例讲解
May 25 Python
PyQt5实现简单的计算器
May 30 Python
python上selenium的弹框操作实现
Jul 13 Python
python实现学生信息管理系统(精简版)
Nov 27 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+dbfile开发小型留言本
2006/10/09 PHP
PHP中冒号、endif、endwhile、endfor使用介绍
2010/04/28 PHP
PHP函数之error_reporting(E_ALL ^ E_NOTICE)详细说明
2011/07/01 PHP
ThinkPHP中的create方法与自动令牌验证实例教程
2014/08/22 PHP
php实现通过soap调用.Net的WebService asmx文件
2017/02/27 PHP
PHP守护进程化在C和PHP环境下的实现
2017/11/21 PHP
PDO::lastInsertId讲解
2019/01/29 PHP
jQuery操作 input type=checkbox的实现代码
2012/06/14 Javascript
js获取TreeView控件选中节点的Text和Value值的方法
2012/11/24 Javascript
详解JS 比较两个Json对象的值是否相等的实例
2013/11/20 Javascript
AngularJS入门教程之数据绑定原理详解
2016/11/02 Javascript
JavaScript实现打地鼠小游戏
2020/04/23 Javascript
nodejs实现爬取网站图片功能
2017/12/14 NodeJs
JavaScript中filter的用法实例分析
2019/02/27 Javascript
js实现双人五子棋小游戏
2020/05/28 Javascript
JavaScript代码模拟鼠标自动点击事件示例
2020/08/07 Javascript
Python修改Excel数据的实例代码
2013/11/01 Python
使用setup.py安装python包和卸载python包的方法
2013/11/27 Python
tensorflow学习教程之文本分类详析
2018/08/07 Python
python 检查是否为中文字符串的方法
2018/12/28 Python
Python实现连接MySql数据库及增删改查操作详解
2019/04/16 Python
Python的Tkinter点击按钮触发事件的例子
2019/07/19 Python
python文件处理fileinput使用方法详解
2020/01/02 Python
python删除某个目录文件夹的方法
2020/05/26 Python
来自南加州灵感的工作和娱乐服装:TravisMathew
2019/05/01 全球购物
亚洲领先的旅游体验市场:Voyagin
2019/11/23 全球购物
如何使用PHP session
2015/04/21 面试题
幼儿园师德演讲稿
2014/05/06 职场文书
节约用电标语
2014/06/17 职场文书
奥林匹克运动会口号
2014/06/19 职场文书
服务标语口号
2014/07/01 职场文书
小学生2014国庆节演讲稿:祖国在我心中
2014/09/21 职场文书
卢旺达饭店观后感
2015/06/05 职场文书
职工培训工作总结
2015/08/10 职场文书
五年级作文之成长
2019/09/16 职场文书
详解Python生成器和基于生成器的协程
2021/06/03 Python