python制作最美应用的爬虫

 更新时间:2015年10月28日 08:57:40   作者:土豆去哪了  
这篇文章主要介绍了python制作最美应用的爬虫的相关资料,需要的朋友可以参考下

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

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('&amp;', '&')
 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操控Chrome浏览器进行网页操作

    Python操控Chrome浏览器进行网页操作

    这篇文章将为您展示如何通过Python控制浏览器实现网页的打开、页面的切换和关闭的基本操作,文中的示例代码讲解详细,感兴趣的可以了解一下
    2023-06-06
  • python基本语法练习实例

    python基本语法练习实例

    下面小编就为大家带来一篇python基本语法练习实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-09-09
  • python如何在列表、字典中筛选数据

    python如何在列表、字典中筛选数据

    这篇文章主要为大家详细介绍了python如何在列表、字典中筛选数据,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-03-03
  • python使用PyGame播放Midi和Mp3文件的方法

    python使用PyGame播放Midi和Mp3文件的方法

    这篇文章主要介绍了python使用PyGame播放Midi和Mp3文件的方法,涉及Python操作多媒体文件的相关技巧,需要的朋友可以参考下
    2015-04-04
  • 如何优雅地处理Django中的favicon.ico图标详解

    如何优雅地处理Django中的favicon.ico图标详解

    默认情况下,浏览器访问一个网站的时候,同时还会向服务器请求"/favicon.ico"这个URL,目的是获取网站的图标,下面这篇文章主要给大家介绍了关于如何优雅地处理Django中favicon.ico图标的相关资料,需要的朋友可以参考下
    2018-07-07
  • Python流程控制常用工具详解

    Python流程控制常用工具详解

    这篇文章主要介绍了Python流程控制常用工具详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-02-02
  • python3中requests库重定向获取URL

    python3中requests库重定向获取URL

    这篇文章主要介绍了python3中requests库重定向获取URL,文章围绕主题展开详细的内容介绍,具有一定的参考价值,需要的小伙伴可以参考一下
    2022-09-09
  • Python matplotlib如何绘制各种流线图

    Python matplotlib如何绘制各种流线图

    在Python中不仅可以绘制折线图、柱状图、散点图等常规图外,还支持绘制量场图、频谱图、提琴图、箱型图等特殊图。本文将主要介绍如何绘制流线图,需要的朋友可以参考一下
    2021-12-12
  • python创建学生成绩管理系统

    python创建学生成绩管理系统

    这篇文章主要为大家详细介绍了python创建学生成绩管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-11-11
  • python Zmail模块简介与使用示例

    python Zmail模块简介与使用示例

    这篇文章主要介绍了python Zmail模块简介与使用示例,帮助大家利用python收发邮件,感兴趣的朋友可以了解下
    2020-12-12

最新评论