推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
xinali
V2EX  ›  Python

python 的一段代码解释

  •  
  •   xinali · Jul 15, 2016 · 4268 views
    This topic created in 3725 days ago, the information mentioned may be changed or developed.
    def check_spider_middleware(method):
    @functools.wraps(method)
    def wrapper(self, request, spider):
        msg = '%%s %s middleware step' % (self.__class__.__name__,)
        if self.__class__ in spider.middleware:
            spider.log(msg % 'executing', level=log.DEBUG)
            return method(self, request, spider)
        else:
            spider.log(msg % 'skipping', level=log.DEBUG)
            return None
    
    return wrapper
    
    

    代码的出处

    主要是这里没看懂,函数可以这么定义吗

    
    def check_spider_middleware(method):
    @functools.wraps(method)
    def wrapper(self, request, spider):
    
    

    这段代码的上面还有一段这个代码

    
    class JsDownload(object):
    
    @check_spider_middleware
    def process_request(self, request, spider):
        driver = webdriver.PhantomJS(executable_path='D:\phantomjs.exe')
        driver.get(request.url)
        return HtmlResponse(request.url, encoding='utf-8', body=driver.page_source.encode('utf-8'))
        
    
    4 replies  •  2016-07-15 16:35:42 +08:00
    alioth310
        1
    alioth310  
       Jul 15, 2016   ❤️ 1
    缩进丢了
    deanguqiang
        2
    deanguqiang  
       Jul 15, 2016 via iPhone
    搜索 装饰器
    quxw
        4
    quxw  
       Jul 15, 2016
    见 1 , 2 楼
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2356 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 00:54 · PVG 08:54 · LAX 17:54 · JFK 20:54
    ♥ Do have faith in what you're doing.