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'))
1
alioth310 2016-07-15 16:10:51 +08:00 1
缩进丢了
|
2
deanguqiang 2016-07-15 16:14:53 +08:00 via iPhone
搜索 装饰器
|
3
raycool 2016-07-15 16:17:48 +08:00 1
|
4
quxw 2016-07-15 16:35:42 +08:00
见 1 , 2 楼
|