爬取爬虫练习网站的书籍信息
专门供爬虫初学者训练爬虫技术的网站(http://books.toscrape.com)
我使用的浏览器是Google Chrome浏览器
1. 创建项目
首先,我们要创建一个Scrapy项目,在shell中使用scrapy startproject命令:
$ scrapy startproject Spider_name
创建成功:
2. 分析页面
网站首页如下图所示:
接着将鼠标停在第一本书的图片上,点击鼠标右键,再选择“检查”。
或者按下F12键。显示如下信息:
可以看到,每一本书的信息包裹在< article class=“product_pod”>元素 中:
书名信息在其下h3 > a元素的title属性中,如< a href="catalogue/a-light- in-the-attic_1000/index.html"title=“A Light in the Attic”>A Light in the…< /a >; 书价信息在其下< p class=“price_c