爬取小米应用商城

# -*-coding:utf8-*-
import requests
import re
import math


j = 1
#查看每一页都多少个APP,用于决定我们要翻多少页
html = requests.get('http://app.mi.com/topList')#获取网页的源代码
label = re.findall('<p class="app-desc">', html.text, re.S)#打开网页源码发现每个App名称前面有<p class="app-desc"># 所有统计这个标示的个数就可以知道每一页有多少个APPpageAppNum = len(label)#label的长度就代表了每一页APP的个数

# print pageAppNum

print(u'请输入App的数目:')
appNum = int(input())
#根据要爬取的APP个数决定要翻多少页
pageNum = math.ceil(float(appNum) / pageAppNum)

for i in range(1, int(pageNum + 1)):
    #html = requests.get('http://app.mi.com/topList?page=' + str(i))#括号内是每一页的连接地址
                        #http://app.mi.com/category/1#page=0
    html = requests.get('http://app.mi.com/category/1#page=' + str(i))

    print(i)
    # print html.text
    title = re.findall('</a><h5><a href=".*?">(.*?)</a></h5><p class="app-desc">', html.text, re.S)#找对应的APP的名称在网页中的位置,并用正则表达式来获取,如果看不懂,那你该好好去看看正则表达式了

    Lab = re.findall('</h5><p class="app-desc"><a href=".*?">(.*?)</a></p>', html.text, re.S)
    #将每一页的APP按先后顺序输出,知道第100    List_title = []
    for title in title:
        if j <= appNum:
            List_title.append(title)
        j = j + 1

    List_Lab = []
    for title in title:
        if j <= appNum:
            List_Lab.append(title)
        j = j + 1
##########################
    print(List_title)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值