zoukankan      html  css  js  c++  java
  • 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端图形化的界面等。

           

  • 相关阅读:
    jvm gc 日志详细信息的输出(一)
    带宽与数据传输速率
    功率半导体器件
    超链接标签a样式生效,取消下划线,文字垂直(上下)居中
    防范诈骗
    去掉table中的空隙
    html中使用js实现内容过长时部分
    背景色透明度设置
    jQuery给标签写入内容
    多个div居中显示
  • 原文地址:https://www.cnblogs.com/wangqiang3311/p/8985450.html
Copyright © 2011-2022 走看看