scrapy shell基本使用方法

Scrapy shell也称"Scrapy终端",是一个交互终端,使我们可以在未启动spider爬虫的情况下尝试及调试代码。

启动

- linux下:ctr+Alt+T打开终端,激活虚拟环境,然后输入:scrapy shell “url”(例:scrapy shell “http://www.baidu.com”)

- windows下:打开终端(如powershell),激活虚拟环境,然后输入:scrapy shell “url”

- 启动后自动下载指定url的网页

- 下载完成后,url的内容保存在response变量中

- 本网站爬取与分析结束后,退出:exit()

response

-          爬取的内容保存在response中

-          response.body是网页的代码

-          response.headers是返回的http的头信息

-          response.xpath() 允许使用xpath语法选择内容

-          response.css() 允许使用css语法选取内容

selector

-          选择器,允许用户使用选择器来选择自己想要的内容

-          response.selector.xpath: response.xpath是response.selector.xpath的快捷方式

-          response.selector.css: response.css是response.selector.css的快捷方式

-          selector.extract: 把节点的内容用unicode形式返回

-          selector.re: 允许用户通过正则选取内容

猜你喜欢

转载自www.cnblogs.com/djlbolgs/p/12506398.html