Request对象
Request(url[, callback, method=‘GET’, headers, body, cookies, meta, encoding=‘utf-8’, priority=0, dont_filter=False, errback])
·url(必选)bytes或str类型,如‘www.csdn.com’
·callback 页面解析函数,Callable类型,Request对象请求的页面下载完成后,由该参数··指定的界面解析函数被调用。如未传递该参数,默认调用Spider的parse方法。
·method HTTP请求的方法,默认’GET’
headers HTTP请求的头部字典,dict类型,例如{'Accept': 'text/html', 'User-
Agent’:Mozilla/5.0’}
·body HTTP请求的正文,bytes或str类型。
·cookies dict类型,例如{‘currency’: ‘USD’, ‘country’: ‘UY’}。
`meta 传递信息
priority 优先级
dont_filter False避免重复下载
Response对象 描述HTTP响应,子类:TextResponse HtmlResponse XmlResponse
url HTTP响应的url地址
·status HTTP响应的状态码
·headers HTTP响应的头头部,可以调用get或gerlist进行访问
·body HTTP响应正文,bytes类型
·text 文本形式HTTP响应正文,str类型,它是由response.body使用response.encoding·解码得到的,即 response.text=response.body.decode(response.encoding)
·encoding HTTP响应正文的编码,它的值可能从HTTP响应头部或正文中解析出来的
·request 产生该HTTP响应的Requst对象
·meta 即response.request.meta 传入
·selector 用于Response中提取数据
·xpath(query) 在Response中提取数据,实际是response.selector.xpath方法
·css(query) 在Response中提取数据,实际是response.selector.css方法
·urljoin(url) 用于构造绝对url,例如response.url为http://www.example.com/a,url为 b/index.html,调用response.urljoin(url)的结果http://www.example.com/a/b/index.html。