Advertisement

python学Python用Scrapy获取链家房源数据存储(轮询)

阅读量:

获取链家租房频道的房源数据,包括多页内容以及各房间详情页面的信息抓取。

items.py

复制代码
 import scrapy

    
  
    
 class ScrapytestItem(scrapy.Item):
    
     # define the fields for your item here like:
    
     title = scrapy.Field()#房源名称
    
     price = scrapy.Field()#价格
    
     url = scrapy.Field()#详情页地址
    
     introduce_item = scrapy.Field()#房源描述
    
    
    
    
    AI写代码python
    
    运行

pipelines.py

复制代码
 import json

    
  
    
 class ScrapytestPipeline(object):
    
     #打开文件
    
     def open_spider(self,spider):
    
     self.file = open('58_chuzu.txt','w',encoding='utf-8')
    
     print('文

全部评论 (0)

还没有任何评论哟~