【Rollo的Python之路】Python 爬虫系统学习 (十一) Scrapy Shell

Scrapy Shell:

语法:

scrapy shell "url"
response.url #当前响应的url地址
response.request.url # 当前响应的请求url地址
response.headers #响应头
response.body #响应体,也就是html代码,默认是bytes类型
response.request.headers #当前响应的请求头

Scrapy 的response与requests里面的response 区别:
Scrapy:response.body 是bytes类型,他没有content属性

Requests: response.content.decode() 就是bytes类型

scrapy shell 可以用来调度,尤其是可以用来测试xpath写法是否正确

猜你喜欢

转载自www.cnblogs.com/rollost/p/11240840.html