python制作最美应用的爬虫

yipeiwu_com5年前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('&', '&')
 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 中xpath爬虫实例详解

python 中xpath爬虫实例详解

案例一: 某套图网站,套图以封面形式展现在页面,需要依次点击套图,点击广告盘链接,最后到达百度网盘展示页面。 这一过程通过爬虫来实现,收集百度网盘地址和提取码,采用xpath爬虫技术...

python爬虫入门教程--快速理解HTTP协议(一)

python爬虫入门教程--快速理解HTTP协议(一)

前言 爬虫的基本原理是模拟浏览器进行 HTTP 请求,理解 HTTP 协议是写爬虫的必备基础,招聘网站的爬虫岗位也赫然写着熟练掌握HTTP协议规范,写爬虫还不得不先从HTTP协议开始讲...

python&MongoDB爬取图书馆借阅记录

python&MongoDB爬取图书馆借阅记录

直接上需求和代码 首先是需要爬取的链接和网页:http://211.81.31.34/uhtbin/cgisirsi/x/0/0/57/49?user_id=LIBSCI_ENGI&pa...

Python多线程、异步+多进程爬虫实现代码

安装Tornado 省事点可以直接用grequests库,下面用的是tornado的异步client。 异步用到了tornado,根据官方文档的例子修改得到一个简单的异步爬虫类。可以参考...

python爬虫实现中英翻译词典

本文实例为大家分享了python爬虫实现中英翻译词典的具体代码,供大家参考,具体内容如下 通过根据某平台的翻译资源,提取出翻译信息,并展示出来,包括输入,翻译,输出三个过程,主要利用py...