码迷,mamicode.com
首页 > 编程语言 > 详细

python爬虫入门-Scrapy基本使用

时间:2017-05-22 15:08:44      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:int   XML   项目   response   ref   headers   pytho   png   enum   

源码:链接:http://pan.baidu.com/s/1dEK82hb 密码:9flo

创建项目                                 scrapy startproject tutorial
爬取                                         scrapy crawl dmoz
爬取并保存为json格式           scrapy crawl dmoz -o items.json -t json

scrapy shell "网址/资源"
载入之后将能得到response的回应
response.body
response.headers
技术分享
>>>response.xpath(‘//title‘)
>>>response.xpath(‘//title/text()‘).extract()

技术分享
 


编辑Item:
技术分享
  1. # -*- coding: utf-8 -*-
  2. # Define here the models for your scraped items
  3. #
  4. # See documentation in:
  5. # http://doc.scrapy.org/en/latest/topics/items.html
  6. import scrapy
  7. class DmozItem(scrapy.Item):
  8. # define the fields for your item here like:
  9. # name = scrapy.Field()
  10. title = scrapy.Field()
  11. link = scrapy.Field()
  12. desc = scrapy.Field()

编辑蜘蛛:
技术分享
 技术分享
 
爬取并保存为json格式
技术分享
至此,根目录下会多出一个json文件
技术分享
 

 




python爬虫入门-Scrapy基本使用

标签:int   XML   项目   response   ref   headers   pytho   png   enum   

原文地址:http://www.cnblogs.com/tcheng/p/6888939.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!