python爬虫框架Pyspider初次接触

  pyspider网站地址:http://docs.pyspider.org/en/latest/。文档比较好,安装起来也非常方便。既然是基于python的框架,那么首先得安装python。微软出的一款编辑软件VSCode,运行速度快,提供了丰富的插件,本人用它安装了python的插件,学习python。

       我分别在Linux、window上都安装过pyspider,window上貌似有问题。以下是我改写的一段代码:

      

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2018-04-18 07:17:21
# Project: emeraldinsight

from pyspider.libs.base_handler import *


class Handler(BaseHandler):
    crawl_config = {
    }

    @every(minutes=24 * 60)
    def on_start(self):
        self.crawl('https://www.emeraldinsight.com/action/doSearch?AllField=computer&content=articlesChapters', callback=self.index_page)

    @config(age=10 * 24 * 60 * 60)
    def index_page(self, response):

        for each in response.doc('.hlFld-Title a').items():
            self.crawl(each.attr.href, callback=self.list_page)

            
    @config(priority=2)
    def list_page(self, response):
        
        downloadurl='https://www.emeraldinsight.com/action/downloadCitation'
        
        detailUrl=response.url
        
        print '详细地址:'+detailUrl
        
        doi=detailUrl.replace('https://www.emeraldinsight.com/doi/full/','')

        print 'doi:'+doi
        
        postdata={
        
         'doi':doi,
         'format':'bibtex'
        }

        self.crawl(downloadurl,callback=self.detail_page,method='POST',data=postdata)

    @config(priority=2)
    def detail_page(self, response):
        print response.text

      这个简单的例子中包含有Get、Post请求以及对文档解析,它采用的是PQuery和JQuery的语法类似,所以上手特别快,几乎不用学习。

      此框架提供了任务调度、队列、文档解析、web端图形化的界面等。

       

转载于:https://www.cnblogs.com/wangqiang3311/p/8985450.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值