apple store 爬虫

本文介绍了一次使用Python的scrapy框架编写爬虫,从Apple Store抓取APP应用信息的经历。作者分享了核心代码,并邀请读者查看、贡献代码,github链接:https://github.com/luotuo/spider-for-apple-store。

前段时间受朋友之托,写了一个爬去Apple store APP应用信息的爬虫。基于scrapy写的。第一次接触scrapy,有很多不太了解的地方。请大家指教。核心代码很短

#! usr/bin/python
# -*- coding: utf-8 -*-

import scrapy
from tutorial.items import TutorialItem
from urllib import unquote
import re


class AppleSpider(scrapy.Spider):
    name = 'apple'
    allowed_domains = ['itunes.apple.com']
    current_category = {}

    def start_requests(self):
        yield scrapy.Request('https://itunes.apple.com/cn/genre/ios/id36?mt=8', self.parse)

    def parse(self, response):
        my_item = TutorialItem()
        app_url = response.url
        app_name = response.xpath('//h1[@itemprop="name"]/text()').extract()
        if len(app_name) > 0:
            category = response.meta['category']
            my_item['app_name'] = app_name[0]
            app_category = response.xpath('//span[@itemprop="applicationCategory"]/text()').extract()
            if len(app_category) > 0:
                my_item['app_category
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值