Spider类的一些自定制
# Spider类 自定义 起始解析器 def start_requests(self): for url in self.start_urls: yield Request(url=url,callback=self.myparse)
# 起始会先经过这个视图函数返回一个 列表或者 一个生成器
yield Request(url=page_url, callback=self.parse) #指定解析函数
parse函数的参数之response
# print(response.request) # 将请求对象也封装在了response中 # print(response.url) # 请求的url # print(response.headers) # 响应的头 # print(response.headers['Set-Cookie']) # 原始cookies ['_auto_detect_fun', '_body', '_body_declared_encoding', '_body_inferred _encoding', '_cached_benc', '_cached_selector', '_cached_ubody', '_declared_encoding', '_encoding', '_get_body', '_get_url', '_headers_encoding', '_se t_body', '_set_url', '_url', 'body', 'body_as_unicode', 'copy', 'css', 'encoding', 'flags', 'follow', 'headers', 'meta', 'replace', 'request', 'select or', 'status', 'text', 'url', 'urljoin', 'xpath']