python爬虫入门(6)-Scrapy基本使用-python爬虫scrapy框架

262次阅读
没有评论

 

创建项目                                 scrapy startproject tutorial

爬取                                         scrapy crawl dmoz

爬取并保存为json格式           scrapy crawl dmoz -o items.json -t json


scrapy shell “网址/资源”

载入之后将能得到response的回应

response.body

response.headers

python爬虫入门(6)-Scrapy基本使用-python爬虫scrapy框架

>>>response.xpath(‘//title’)

>>>response.xpath(‘//title/text()’).extract()

 

python爬虫入门(6)-Scrapy基本使用-python爬虫scrapy框架

 


编辑Item:

python爬虫入门(6)-Scrapy基本使用-python爬虫scrapy框架

    # -*- coding: utf-8 -*-     # Define here the models for your scraped items     #     # See documentation in:     # http://doc.scrapy.org/en/latest/topics/items.html     import scrapy     class DmozItem(scrapy.Item):         # define the fields for your item here like:         # name = scrapy.Field()         title = scrapy.Field()         link = scrapy.Field()         desc = scrapy.Field()

 

 

编辑蜘蛛:

python爬虫入门(6)-Scrapy基本使用-python爬虫scrapy框架

 python爬虫入门(6)-Scrapy基本使用-python爬虫scrapy框架

 

爬取并保存为json格式

python爬虫入门(6)-Scrapy基本使用-python爬虫scrapy框架

至此,根目录下会多出一个json文件

python爬虫入门(6)-Scrapy基本使用-python爬虫scrapy框架

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:Python教程2022-11-01发表,共计706字。
新手QQ群:570568346,欢迎进群讨论 Python51学习