爬虫-python-scrapy框架基本命令
创建一个项目
scrapy startproject name
抓取页面
scrapy crawl 抓取的模块名
网页抓取shell
scrapy shell "目标URL"
//进入shell,获取响应实体
response.body
response.headers
XPath(选择器节点)
//方法
1. text() 获取标签中的文字
2. extract() 获取节点中的文字转换成unicode编码
3. response.xpath('//ul/li/text()').extract() 获取对应节点的文字,转换成unicode编码
4. response.xpath('//ul/li/a/@href').extract()
获取a标签中的URL地址,转换成文字
5. response.xpath('//div[@class="site-title"]/text()').extract()
获取div且class=“site-title”的标签内文章,转换成文字
数据导出
scrapy crawl dmoz -o items.json -t json